Sha256: ed804fe3929e7f097d61cb7b7f58a4ce5c566511b1c183b949ef42e4cc7476a6
Contents?: true
Size: 1013 Bytes
Versions: 44
Compression:
Stored size: 1013 Bytes
Contents
class Brief::Document::Section attr_accessor :title, :fragment attr_reader :config Headings = %w(h1 h2 h3 h4 h5 h6) def initialize(title, fragment, config) @title = title @fragment = fragment @config = config end def to_html fragment.to_html end def text fragment.text end 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 end
Version data entries
44 entries across 44 versions & 1 rubygems