Class: Cldr::Export::Data::Currencies

Inherits:
Base
  • Object
show all
Defined in:
lib/cldr/export/data/currencies.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) ⇒ Currencies

Returns a new instance of Currencies.



5
6
7
8
# File 'lib/cldr/export/data/currencies.rb', line 5

def initialize(locale)
  super
  update(:currencies => currencies)
end

Instance Method Details

#currenciesObject



10
11
12
13
14
15
16
# File 'lib/cldr/export/data/currencies.rb', line 10

def currencies
  select('numbers/currencies/*').inject({}) do |result, node|
    currency = self.currency(node)
    result[node.attribute('type').value.to_sym] = currency unless currency.empty?
    result
  end
end

#currency(node) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cldr/export/data/currencies.rb', line 18

def currency(node)
  data = select(node, 'displayName').inject({}) do |result, node|
    unless draft?(node)
      if node.attribute('count')
        count = node.attribute('count').value.to_sym
        result[count] = node.content
      else
        result[:one] = node.content if result[:one].nil?
        result[:name] = node.content
      end
    end

    result
  end

  symbol = select(node, 'symbol')
  narrow_symbol = symbol.select { |child_node| child_node.values.include?('narrow') }.first
  data[:symbol] = symbol.first.content if symbol.length > 0
  data[:'narrow_symbol'] = narrow_symbol.content unless narrow_symbol.nil?

  data
end