Class: Cldr::Export::Data::Numbers

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

Returns a new instance of Numbers.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cldr/export/data/numbers.rb', line 5

def initialize(locale)
  super
  update(
    :numbers => {
      :symbols => symbols,
      :formats => {
        :decimal => {
          :number_system => number_system('decimal'),
          :patterns => format('decimal')
        },
        :scientific => {
          :number_system => number_system('scientific'),
          :patterns => format('scientific')
        },
        :percent => {
          :number_system => number_system('percent'),
          :patterns => format('percent')
        },
        :currency => {
          :number_system => number_system('currency'),
          :patterns => format('currency'),
          :unit => unit
        }
      }
    }
  )
end

Instance Method Details

#currencyObject



33
34
35
36
37
# File 'lib/cldr/export/data/numbers.rb', line 33

def currency
  currency = format('currency')
  currency.update(:unit => unit) unless unit.empty?
  currency
end

#format(type) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cldr/export/data/numbers.rb', line 46

def format(type)
  result = select("numbers/#{type}Formats/#{type}FormatLength/#{type}Format").inject({}) do |format_result, format_node|
    format_key = format_node.parent.attribute('type')
    format_result[format_key ? format_key.value : :default] = select(format_node, "pattern").inject({}) do |pattern_result, pattern_node|
      pattern_key = pattern_node.attribute('type')
      pattern_result[pattern_key ? pattern_key.value : :default] = pattern_node.content unless draft?(pattern_node)
      pattern_result
    end
    format_result
  end

  result[:default] = result[:default][:default] if result[:default]
  result
end

#number_system(type) ⇒ Object



61
62
63
64
# File 'lib/cldr/export/data/numbers.rb', line 61

def number_system(type)
  node = select("numbers/#{type}Formats").first
  node.attribute('numberSystem').value rescue "latn"
end

#symbolsObject



39
40
41
42
43
44
# File 'lib/cldr/export/data/numbers.rb', line 39

def symbols
  select('numbers/symbols/*').inject({}) do |result, node|
    result[name(node).to_sym] = node.content unless draft?(node)
    result
  end
end

#unitObject



66
67
68
69
70
71
72
# File 'lib/cldr/export/data/numbers.rb', line 66

def unit
  @unit ||= select("numbers/currencyFormats/unitPattern").inject({}) do |result, node|
    count = node.attribute('count').value rescue 'one'
    result[count] = node.content
    result
  end
end