utils.ParseErrors   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
package utils
2
3
import (
4
	"regexp"
5
6
	"github.com/SerhiiCho/shoshka-go/models"
7
)
8
9
// GetPostsFromHTML returns all html posts
10
func GetPostsFromHTML(html *string) []string {
11 1
	linksRegex := "<article class(.|\n)*?<\\/article>"
12 1
	return regexp.MustCompile(linksRegex).FindAllString(*html, -1)
13
}
14
15
// GetAllInformation parses anchor tags and takes image src,
16
// link url and title.
17
func GetAllInformation(html *[]string) []models.PhotoReport {
18 1
	var photoReport models.PhotoReport
19 1
	var result []models.PhotoReport
20
21 1
	compiledTitle := regexp.MustCompile("<h3 (.|\\n)*?[^ ]>(.*)<\\/a>")
22 1
	compiledImage := regexp.MustCompile(" src=\"([\\S]+)\" ")
23 1
	compiledURL := regexp.MustCompile(" href=[\"|']([\\S]+)(\"|') ")
24
25 1
	for _, tag := range *html {
26 1
		photoReport.Title = compiledTitle.FindStringSubmatch(tag)[2]
27 1
		photoReport.Image = compiledImage.FindStringSubmatch(tag)[1]
28 1
		photoReport.URL = compiledURL.FindStringSubmatch(tag)[1]
29
30 1
		result = append(result, photoReport)
31
	}
32
33 1
	return result
34
}
35
36
// ParseErrors returns slice of errors
37
func ParseErrors(text string) []string {
38 1
	return regexp.MustCompile("\\[([A-z0-9 :-]+)\\] (.*)").FindAllString(text, -1)
39
}
40