Class: Cldr::Export::Data::Numbers
- Inherits:
-
Base
- Object
- Hash
- Base
- Cldr::Export::Data::Numbers
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
#currency ⇒ Object
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
|
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/cldr/export/data/numbers.rb', line 46
def format(type)
result = select("numbers/#{type}Formats/#{type}FormatLength").inject({}) do |format_result, format_length_node|
format_nodes = select(format_length_node, "#{type}Format")
format_key = format_length_node.attribute('type')
format_key = format_key ? format_key.value : :default
if format_nodes.size > 0
format_nodes.each do |format_node|
format_result[format_key] ||= select(format_node, "pattern").inject({}) do |pattern_result, pattern_node|
pattern_key_node = pattern_node.attribute('type')
pattern_count_node = pattern_node.attribute('count')
unless draft?(pattern_node)
pattern_key = pattern_key_node ? pattern_key_node.value : :default
if pattern_count_node
pattern_count = pattern_count_node.value
if pattern_result[pattern_key].nil?
pattern_result[pattern_key] ||= {}
elsif !pattern_result[pattern_key].is_a?(Hash)
raise "can't parse patterns with and without 'count' attribute in the same section"
end
pattern_result[pattern_key][pattern_count] = pattern_node.content
else
pattern_result[pattern_key] = pattern_node.content
end
end
pattern_result
end
end
else
aliased = select(format_length_node, 'alias').first
if aliased
format_result[format_key] = xpath_to_redirect(aliased.attribute('path').value)
end
end
format_result
end
result[:default] = result[:default][:default] if result[:default]
result
end
|
#number_system(type) ⇒ Object
103
104
105
106
|
# File 'lib/cldr/export/data/numbers.rb', line 103
def number_system(type)
node = select("numbers/#{type}Formats").first
node.attribute('numberSystem').value rescue "latn"
end
|
#symbols ⇒ Object
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
|
#unit ⇒ Object
108
109
110
111
112
113
114
|
# File 'lib/cldr/export/data/numbers.rb', line 108
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
|
#xpath_to_redirect(xpath) ⇒ Object
96
97
98
99
100
101
|
# File 'lib/cldr/export/data/numbers.rb', line 96
def xpath_to_redirect(xpath)
length = xpath[/(\w+)FormatLength/, 1]
type = xpath[/@type='(\w+)'/, 1]
:"numbers.formats.#{length}.patterns.#{type}"
end
|