Skip to content

Commit

Permalink
Export currency names
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Wang committed Jun 6, 2019
1 parent 8b7e917 commit 3e8c8d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 11 additions & 3 deletions lib/cldr/export/data/currencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ def currencies

def currency(node)
data = select(node, 'displayName').inject({}) do |result, node|
count = node.attribute('count') ? node.attribute('count').value.to_sym : :one
result[count] = node.content unless draft?(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

Expand All @@ -30,4 +38,4 @@ def currency(node)
end
end
end
end
end
7 changes: 6 additions & 1 deletion test/export/data/currencies_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ class TestCldrCurrencies < Test::Unit::TestCase
currencies = Cldr::Export::Data::Currencies.new('de')[:currencies]
assert_empty codes - currencies.keys, "Unexpected missing currencies"
assert_empty currencies.keys - codes, "Unexpected extra currencies"
assert_equal({ :one => 'Euro', :other => 'Euro', :symbol => '€' }, currencies[:EUR])
assert_equal({ :name => 'Euro', :one => 'Euro', :other => 'Euro', :symbol => '€' }, currencies[:EUR])
end

test 'currencies uses the label to populate :one when count is unavailable' do
currencies = Cldr::Export::Data::Currencies.new('ak')[:currencies]
assert_equal({ :name => 'Yuan', :one => 'Yuan' }, currencies[:CNY])
end

# Cldr::Export::Data.locales.each do |locale|
Expand Down

0 comments on commit 3e8c8d7

Please sign in to comment.