Skip to content

Commit

Permalink
Export narrow symbols from relevant currencies (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
camertron authored Nov 19, 2020
2 parents 3412fd4 + 7c84c98 commit e54cca8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Added root fallback to en language, [#47](https://github.com/ruby-i18n/ruby-cldr/pull/47)
- Added subdivisions to the list of exportable components, [#46](https://github.com/ruby-i18n/ruby-cldr/pull/46)
- Added country codes as an exportable component, [#61](https://github.com/ruby-i18n/ruby-cldr/pull/61)
- Added narrow symbols to exported currency data, [#64](https://github.com/ruby-i18n/ruby-cldr/pull/64)

---

Expand Down
2 changes: 2 additions & 0 deletions lib/cldr/export/data/currencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def currency(node)
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
Expand Down
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({ :name => 'Euro', :one => 'Euro', :other => 'Euro', :symbol => '€' }, currencies[:EUR])
assert_equal({ :name => 'Euro', :'narrow_symbol'=>'€', :one => 'Euro', :other => 'Euro', :symbol => '€' }, currencies[:EUR])
end

test 'currencies populates symbol-narrow when narrow symbol is not equal to the regular symbol' do
currencies = Cldr::Export::Data::Currencies.new('root')[:currencies]
assert_equal({ :symbol=>'US$', :'narrow_symbol'=>'$'}, currencies[:USD])
end

test 'currencies uses the label to populate :one when count is unavailable' do
Expand Down

0 comments on commit e54cca8

Please sign in to comment.