utils/regex_utils.go   A
last analyzed

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
cc 4
eloc 21
dl 0
loc 38
ccs 14
cts 14
cp 1
crap 4
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A utils.GetAllInformation 0 17 2
A utils.GetPostsFromHTML 0 3 1
A utils.ParseErrors 0 2 1
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