Class: Semantic::Mapper::Markup

Inherits:
Object
  • Object
show all
Defined in:
lib/semantic/mapper/markup.rb

Constant Summary collapse

SELECTOR =
'[data-mapping]'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ Markup

Returns a new instance of Markup.



7
8
9
10
# File 'lib/semantic/mapper/markup.rb', line 7

def initialize(html)
  @html = html
  @mapped_hash = HashWithIndifferentAccess.new
end

Instance Attribute Details

#mapped_hashObject (readonly)

Returns the value of attribute mapped_hash.



5
6
7
# File 'lib/semantic/mapper/markup.rb', line 5

def mapped_hash
  @mapped_hash
end

Instance Method Details

#mapObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/semantic/mapper/markup.rb', line 12

def map
  document.css(SELECTOR).each do |element|
    fields(element).each do |key| 
      final_attribute_value = attribute_value(element, 'name')
      keys = build_keys(key)
      map_hash(final_attribute_value, keys)
    end 
  end
  @mapped_hash
end