Class: Tenet::Row
- Inherits:
-
Object
- Object
- Tenet::Row
- Defined in:
- lib/tenet/row.rb
Instance Method Summary collapse
-
#initialize(html, attributes, parser = Nokogiri::HTML5) ⇒ Row
constructor
A new instance of Row.
- #to_h ⇒ Hash
Constructor Details
#initialize(html, attributes, parser = Nokogiri::HTML5) ⇒ Row
Returns a new instance of Row.
9 10 11 12 13 |
# File 'lib/tenet/row.rb', line 9 def initialize(html, attributes, parser = Nokogiri::HTML5) @html = html @attributes = attributes @document = parser.parse(@html) end |
Instance Method Details
#to_h ⇒ Hash
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tenet/row.rb', line 18 def to_h values = {} @attributes.each do |attribute| selector = @document.css(attribute.css).first case attribute.type when :string value = selector.content when :link value = selector[:href] when :img value = selector[:src] end values[attribute.name] = value end values end |