Class: Cldr::Data::Units

Inherits:
Base show all
Defined in:
lib/cldr/data/units.rb

Instance Attribute Summary

Attributes inherited from Base

#locale

Instance Method Summary collapse

Methods inherited from Base

#[]=, #update

Methods inherited from Hash

#deep_merge, #deep_stringify_keys, #symbolize_keys

Constructor Details

#initialize(locale) ⇒ Units

Returns a new instance of Units.



4
5
6
7
# File 'lib/cldr/data/units.rb', line 4

def initialize(locale)
  super
  self[:units] = units
end

Instance Method Details

#unit(node) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/cldr/data/units.rb', line 16

def unit(node)
  node.xpath('unitPattern').inject({}) do |result, node|
    count = node.attribute('count') ? node.attribute('count').value.to_sym : :one
    result[count] = node.content unless draft?(node)
    result
  end
end

#unitsObject



9
10
11
12
13
14
# File 'lib/cldr/data/units.rb', line 9

def units
  select('units/unit').inject({}) do |result, node|
    result[node.attribute('type').value.to_sym] = unit(node)
    result
  end
end