Skip to content

Commit

Permalink
Merge pull request #146 from jlduran/refactor-spanish
Browse files Browse the repository at this point in the history
Refactor Spanish
  • Loading branch information
dblock authored Jul 21, 2017
2 parents 7f92a9f + 620200c commit 9c112b9
Show file tree
Hide file tree
Showing 22 changed files with 432 additions and 92 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ AllCops:
Exclude:
- 'numbers_and_words.gemspec'

Style/AsciiComments:
Enabled: false

Style/FileName:
Enabled: false
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
## 0.11.1 (Next)
* Add support for French floating numbers \[[#144](https://github.com/kslazarev/numbers_and_words/pull/144)\]

### Features
* Your contribution here.
* Add support for Spanish floating-point numbers \[[#146](https://github.com/kslazarev/numbers_and_words/pull/146)\]
* Add support for French floating-point numbers \[[#144](https://github.com/kslazarev/numbers_and_words/pull/144)\]

## 0.11.0 (June 26, 2017)

Expand Down
111 changes: 86 additions & 25 deletions lib/numbers_and_words/i18n/locales/numbers.es.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,103 @@
es:
numbers:
one: un
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: [_, thousand, million, billion, trillion, quadrillion, quintillion, sextillion, septillion, octillion, nonillion, decillion, undecillion, duodecillion, tredecillion, quattuordecillion]
thousand: mil
million:
ones:
apocopated: un
male: [cero, uno, dos, tres, cuatro, cinco, seis, siete, ocho, nueve]
female: [cero, una, dos, tres, cuatro, cinco, seis, siete, ocho, nueve]
teens: [_, once, doce, trece, catorce, quince, dieciséis, diecisiete, dieciocho, diecinueve]
tens: [_, diez, veinte, treinta, cuarenta, cincuenta, sesenta, setenta, ochenta, noventa]
twenties:
apocopated: veintiún
male: [_, veintiuno, veintidós, veintitrés, veinticuatro, veinticinco, veintiséis, veintisiete, veintiocho, veintinueve]
female: [_, veintiuna, veintidós, veintitrés, veinticuatro, veinticinco, veintiséis, veintisiete, veintiocho, veintinueve]
hundreds:
apocopated: cien
male: [_, ciento, doscientos, trescientos, cuatrocientos, quinientos, seiscientos, setecientos, ochocientos, novecientos]
female: [_, ciento, doscientas, trescientas, cuatrocientas, quinientas, seiscientas, setecientas, ochocientas, novecientas]
mega: [_, thousands, millions, billions, trillions, quadrillions, quintillions, sextillions, septillions, octillions, nonillions, decillions, undecillions, duodecillions, tredecillions, quattuordecillions]
thousands: mil
millions:
one: millón
other: millones
billion: mil millones
trillion:
billions: mil millones
trillions:
one: billón
other: billones
quadrillion: mil billones
quintillion:
quadrillions: mil billones
quintillions:
one: trillón
other: trillones
sextillion: mil trillones
septillion:
sextillions: mil trillones
septillions:
one: cuatrillón
other: cuatrillones
octillion: mil cuatrillones
nonillion:
octillions: mil cuatrillones
nonillions:
one: quintillón
other: quintillones
decillion: mil quintillones
undecillion:
decillions: mil quintillones
undecillions:
one: sextillón
other: sextillones
duodecillion: mil sextillones
tredecillion:
duodecillions: mil sextillones
tredecillions:
one: septillón
other: septillones
quattuordecillion: mil septillones
quattuordecillions: mil septillones
union_separator: con
micro: [_, tenths, hundredths, thousandths, millionths, billionths, trillionths, quadrillionths, quintillionths, sextillionths, septillionths, octillionths, nonillionths, decillionths, undecillionths, duodecillionths, tredecillionths, quattuordecillionths]
micro_prefix:
tens: diez
hundreds: cien
tenths:
one: décima
other: décimas
hundredths:
one: centésima
other: centésimas
thousandths:
one: milésima
other: milésimas
millionths:
one: millonésima
other: millonésimas
billionths:
one: milmillonésima
other: milmillonésimas
trillionths:
one: billonésima
other: billonésimas
quadrillionths:
one: milbillonésima
other: milbillonésimas
quintillionths:
one: trillonésima
other: trillonésimas
sextillionths:
one: miltrillonésima
other: miltrillonésimas
septillionths:
one: cuatrillonésima
other: cuatrillonésimas
octillionths:
one: milcuatrillonésima
other: milcuatrillonésimas
nonillionths:
one: quintillonésima
other: quintillonésimas
decillionths:
one: milquintillonésima
other: milquintillonésimas
undecillionths:
one: sextillonésima
other: sextillonésimas
duodecillionths:
one: milsextillonésima
other: milsextillonésimas
tredecillionths:
one: septillonésima
other: septillonésimas
quattuordecillionths:
one: milseptillonésima
other: milseptillonésimas
union: y
1 change: 1 addition & 0 deletions lib/numbers_and_words/strategies/array_joiner/languages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

require 'numbers_and_words/strategies/array_joiner/languages/en'
require 'numbers_and_words/strategies/array_joiner/languages/en-GB'
require 'numbers_and_words/strategies/array_joiner/languages/es'
require 'numbers_and_words/strategies/array_joiner/languages/fr'
require 'numbers_and_words/strategies/array_joiner/languages/hu'
require 'numbers_and_words/strategies/array_joiner/languages/ru'
Expand Down
10 changes: 10 additions & 0 deletions lib/numbers_and_words/strategies/array_joiner/languages/es.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module NumbersAndWords
module Strategies
module ArrayJoiner
module Languages
class Es < Base
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'numbers_and_words/strategies/figures_converter/decorators/base'
require 'numbers_and_words/strategies/figures_converter/decorators/en'
require 'numbers_and_words/strategies/figures_converter/decorators/en-GB'
require 'numbers_and_words/strategies/figures_converter/decorators/es'
require 'numbers_and_words/strategies/figures_converter/decorators/fr'
require 'numbers_and_words/strategies/figures_converter/decorators/ru'
require 'numbers_and_words/strategies/figures_converter/decorators/pt-BR'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'numbers_and_words/strategies/figures_converter/decorators/es/base'
require 'numbers_and_words/strategies/figures_converter/decorators/es/fractional'
require 'numbers_and_words/strategies/figures_converter/decorators/es/integral'
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module NumbersAndWords
module Strategies
module FiguresConverter
module Decorators
module Es
class Base < Decorators::Base
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module NumbersAndWords
module Strategies
module FiguresConverter
module Decorators
module Es
class Fractional < Base
def run
@options[:gender] = :female
"#{super} #{fraction_significance}"
end

private

def fraction_significance
@strategy.translations.micros full_fraction.fraction_capacity, figures.join.to_i
end

def full_fraction
(0..zero_length).inject(figures.clone) { |result, _el| result.unshift 0 }.to_figures
end

def figures
@strategy.figures
end

def zero_length
fraction_length - figures.length
end

def fraction_length
@options[:fractional][:length].to_i
end
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module NumbersAndWords
module Strategies
module FiguresConverter
module Decorators
module Es
class Integral < Base
end
end
end
end
end
end
75 changes: 50 additions & 25 deletions lib/numbers_and_words/strategies/figures_converter/languages/es.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,72 @@ class Es < Base
include Families::Latin

def capacity_iteration
words = []
capacity_words = words_in_capacity(@current_capacity)
words.push megs unless capacity_words.empty?
super.compact
end

def zero
super unless maybe_remove_zero
end

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
def ones
super({ gender: gender,
is_one_thousand: one_thousand?,
is_apocopated: one_apocopated? })
end

words + capacity_words
def tens_with_ones
if @figures.tens == 2
@translations
.twenties_with_ones(@figures, gender: gender,
is_apocopated: one_apocopated?)
else
super({ gender: gender,
is_apocopated: one_apocopated? })
end
end

def hundreds
super({ is_hundred: (figures[1, 2] == [0, 1] &&
simple_number_to_words.empty?) })
super({ gender: gender,
is_apocopated: hundred_apocopated? })
end

def megs
if thousand? &&
@figures.number_in_capacity(@current_capacity - 1) != 0
@translations.thousand
else
super({ number: @figures.number_in_capacity(@current_capacity) })
end
return @translations.megs(1, number: 1) if long_scale_thousand?
super({ number: @figures.number_in_capacity(@current_capacity) })
end

private

def one?
words_in_capacity(@current_capacity) == [@translations.ones(1)]
def one_thousand?
@current_capacity.odd? &&
@figures.ones == 1 &&
@figures.tens.nil? &&
@figures.hundreds.nil?
end

def thousand?
@current_capacity.odd?
def long_scale_thousand?
@current_capacity.odd? &&
@figures.number_in_capacity(@current_capacity - 1) != 0
end

def one_apocopated?
true if @current_capacity > 0 && @figures.ones == 1 ||
@options.apocopated.result
end

def hundred_apocopated?
@figures.hundreds == 1 && @figures.round_hundred?
end

def gender
@current_capacity ||= 0

return 'male'.to_sym if @current_capacity >= 2
@options.gender.result
end

def twenty_one?
figures.reverse[0..1] == [2, 1]
def maybe_remove_zero
@options.remove_zero.result
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ module FiguresConverter
module Languages
module Families
module Helpers
[:zero].each do |method_name|
define_method(method_name) do |*args|
options = args.first || {}
translate method_name, options
end
def zero(*args)
options = args.first || {}
translate :zero, options
end

%i[ones teens tens tens_with_ones hundreds].each do |method_name|
Expand All @@ -18,11 +16,9 @@ module Helpers
end
end

[:megs].each do |method_name|
define_method(method_name) do |*args|
options = args.first || {}
translate method_name, @current_capacity, options
end
def megs(*args)
options = args.first || {}
translate :megs, @current_capacity, options
end

def translate(method_name, *args)
Expand Down
5 changes: 3 additions & 2 deletions lib/numbers_and_words/strategies/figures_converter/options.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require 'numbers_and_words/strategies/figures_converter/options/en'
require 'numbers_and_words/strategies/figures_converter/options/en-GB'
require 'numbers_and_words/strategies/figures_converter/options/ru'
require 'numbers_and_words/strategies/figures_converter/options/es'
require 'numbers_and_words/strategies/figures_converter/options/hu'
require 'numbers_and_words/strategies/figures_converter/options/pt-BR'
require 'numbers_and_words/strategies/figures_converter/options/ru'
require 'numbers_and_words/strategies/figures_converter/options/ua'
require 'numbers_and_words/strategies/figures_converter/options/hu'

module NumbersAndWords
module Strategies
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'numbers_and_words/strategies/figures_converter/options/es/apocopated'
require 'numbers_and_words/strategies/figures_converter/options/es/gender'
require 'numbers_and_words/strategies/figures_converter/options/es/remove_zero'
Loading

0 comments on commit 9c112b9

Please sign in to comment.