Class: PriceTag::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/pricetag/document.rb

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ Document

Returns a new instance of Document.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/pricetag/document.rb', line 3

def initialize(html)
  @xml = Nokogiri::HTML("<root>" + html + "</root>") do |config|
    config.strict.noent
  end

  @references = []
  @xml.search("a").each do |a|
    @references << [a['href'], a['title']]
    a['data-reference-number'] = @references.length.to_s
  end
  
  @xml.search("li").each do |li|
    li['data-position'] = (li.parent.search("li").index(li) + 1).to_s
  end
end