21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/brief/document/section.rb', line 21
def items
return @items if @items
data = []
config.selectors.each do |selector|
settings = config.selector_config[selector]
if Headings.include?(selector)
headings = fragment.css('article > h2')
articles = headings.map(&:parent)
unless settings.empty?
articles.compact.each do |article|
data.push(settings.inject({}.to_mash) do |memo, pair|
attribute, selector = pair
result = article.css(selector)
memo[attribute] = result.length > 1 ? result.map(&:text) : result.text
memo
end)
end
end
end
end
@items = data
end
|