Class: Tenet::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/tenet/row.rb

Instance Method Summary collapse

Constructor Details

#initialize(html, attributes, parser = Nokogiri::HTML5) ⇒ Row

Returns a new instance of Row.

Parameters:

  • html (String)
  • attributes (Hash)


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_hHash

Returns:

  • (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