Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ES big numbers #129

Merged
merged 1 commit into from
Apr 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Your contribution here.

### Bugs
* Fix big numbers in Spanish. \[[#129](https://github.com/kslazarev/numbers_and_words/pull/129)\] \([@jlduran](https://github.com/jlduran)\) \(assignee: [@jlduran](https://github.com/jlduran)\)
* Fix typo for number twenty-one in Spanish. \[[#127](https://github.com/kslazarev/numbers_and_words/pull/127)\] \([@jlduran](https://github.com/jlduran)\) \(assignee: [@jlduran](https://github.com/jlduran)\)

## 0.10.5 (March 9, 2016)
Expand Down
35 changes: 30 additions & 5 deletions lib/numbers_and_words/i18n/locales/numbers.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,39 @@ es:
ones: [cero, uno, dos, tres, cuatro, cinco, seis, siete, ocho, nueve]
one_twenties: ún
ones_twenties: [_, uno, dós, trés, cuatro, cinco, séis, siete, ocho, nueve]

teens: [diez, once, doce, trece, catorce, quince, dieciséis, diecisiete, dieciocho, diecinueve]
tens: [_, diez, veinti, treinta, cuarenta, cincuenta, sesenta, setenta, ochenta, noventa]
twenty: veinte

hundreds: [ciento, doscientos, trescientos, cuatrocientos, quinientos, seiscientos, setecientos, ochocientos, novecientos]
one_hundred: cien

mega: [_, mil, millón, mil millones, billón, mil billones, trillón, mil trillones, cuatrillón, mil cuatrillones, quintillón, mil quintillones]
megas: [_, mil, millones, mil millones, billones, mil billones, trillones, mil trillones, cuatrillones, mil cuatrillones, quintillones, mil quintillones]
mega: [_, thousand, million, billion, trillion, quadrillion, quintillion, sextillion, septillion, octillion, nonillion, decillion, undecillion, duodecillion, tredecillion, quattuordecillion]
thousand: mil
million:
one: millón
other: millones
billion: mil millones
trillion:
one: billón
other: billones
quadrillion: mil billones
quintillion:
one: trillón
other: trillones
sextillion: mil trillones
septillion:
one: cuatrillón
other: cuatrillones
octillion: mil cuatrillones
nonillion:
one: quintillón
other: quintillones
decillion: mil quintillones
undecillion:
one: sextillón
other: sextillones
duodecillion: mil sextillones
tredecillion:
one: septillón
other: septillones
quattuordecillion: mil septillones
union: y
31 changes: 17 additions & 14 deletions lib/numbers_and_words/strategies/figures_converter/languages/es.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ class Es < Base
def capacity_iteration
words = []
capacity_words = words_in_capacity(@current_capacity)
words.push megs(capacity_words) unless capacity_words.empty?

if 0 < @current_capacity
capacity_words = capacity_words.map do |word|
if twenty_one?
word.gsub(@translations.ones(1), @translations.one_twenties)
elsif !thousand? || !one?
word.gsub(@translations.ones(1), @translations.one)
end
end.compact
end
words.push megs unless capacity_words.empty?

capacity_words = capacity_words.map do |word|
if twenty_one?
word.gsub(@translations.ones(1), @translations.one_twenties)
elsif !thousand? || !one?
word.gsub(@translations.ones(1), @translations.one)
end
end.compact

words + capacity_words
end
Expand All @@ -28,14 +26,19 @@ def hundreds
simple_number_to_words.empty?) })
end

def megs(capacity_words)
super({ is_one: capacity_words == [@translations.ones(1)] })
def megs
if thousand? &&
@figures.number_in_capacity(@current_capacity - 1) != 0
@translations.thousand
else
super({ number: @figures.number_in_capacity(@current_capacity) })
end
end

private

def one?
[translations.ones(1)] == words_in_capacity(@current_capacity)
[@translations.ones(1)] == words_in_capacity(@current_capacity)
end

def thousand?
Expand Down
5 changes: 2 additions & 3 deletions lib/numbers_and_words/translations/es.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ def hundreds(number, options = {})
options[:is_hundred] ? t(:one_hundred) : t(:hundreds)[number - 1]
end

def megs(capacity, options = {})
options[:is_one] = false if options[:is_one].nil?
options[:is_one] ? t(:mega)[capacity] : t(:megas)[capacity]
def thousand
t(:thousand)
end
end
end
Expand Down
13 changes: 7 additions & 6 deletions spec/numbers_and_words/integer/fixture_examples/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ to_words:
999999000: novecientos noventa y nueve millones novecientos noventa y nueve mil
999999999: novecientos noventa y nueve millones novecientos noventa y nueve mil novecientos noventa y nueve
billions:
1174315110: mil millones ciento setenta y cuatro millones trescientos quince mil ciento diez
1174315119: mil millones ciento setenta y cuatro millones trescientos quince mil ciento diecinueve
15174315119: quince mil millones ciento setenta y cuatro millones trescientos quince mil ciento diecinueve
35174315119: treinta y cinco mil millones ciento setenta y cuatro millones trescientos quince mil ciento diecinueve
935174315119: novecientos treinta y cinco mil millones ciento setenta y cuatro millones trescientos quince mil ciento diecinueve
1000000000: mil millones
1174315110: mil ciento setenta y cuatro millones trescientos quince mil ciento diez
1174315119: mil ciento setenta y cuatro millones trescientos quince mil ciento diecinueve
15174315119: quince mil ciento setenta y cuatro millones trescientos quince mil ciento diecinueve
35174315119: treinta y cinco mil ciento setenta y cuatro millones trescientos quince mil ciento diecinueve
935174315119: novecientos treinta y cinco mil ciento setenta y cuatro millones trescientos quince mil ciento diecinueve
trillions:
2935174315119: dos billones novecientos treinta y cinco mil millones ciento setenta y cuatro millones trescientos quince mil ciento diecinueve
2935174315119: dos billones novecientos treinta y cinco mil ciento setenta y cuatro millones trescientos quince mil ciento diecinueve