Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
No functional change
  • Loading branch information
jlduran committed Aug 6, 2017
1 parent d976f02 commit 3355822
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/numbers_and_words/i18n/locales/numbers.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ es:
one: septillón
other: septillones
quattuordecillions: mil septillones
union_separator: con
union: y
micro: [_, tenths, hundredths, thousandths, millionths, billionths, trillionths, quadrillionths, quintillionths, sextillionths, septillionths, octillionths, nonillionths, decillionths, undecillionths, duodecillionths, tredecillionths, quattuordecillionths]
micro_prefix:
tens: diez
Expand Down Expand Up @@ -100,4 +100,4 @@ es:
quattuordecillionths:
one: milseptillonésima
other: milseptillonésimas
union: y
union_separator: con
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def hundred_apocopated?
def gender
@current_capacity ||= 0

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def check_megs_numbers

def simple_numbers_condition
current_capacity.nil? &&
(HUNDRED_TYPE != @type || (HUNDRED_TYPE == @type && simple_number_to_words.empty?))
(HUNDRED_TYPE != @type ||
HUNDRED_TYPE == @type && simple_number_to_words.empty?)
end

def megs_numbers_condition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def check_megs_numbers

def simple_numbers_condition
current_capacity.nil? &&
(HUNDRED_TYPE != @type || (HUNDRED_TYPE == @type && simple_number_to_words.empty?))
(HUNDRED_TYPE != @type ||
HUNDRED_TYPE == @type && simple_number_to_words.empty?)
end

def megs_numbers_condition
Expand Down
12 changes: 5 additions & 7 deletions lib/numbers_and_words/translations/es.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def zero(_options = {})

def ones(number, options = {})
return if options[:is_one_thousand]
return t(%i[ones apocopated].join('.')) if options[:is_apocopated]
return t(%i[ones apocopated].join('.')) if number == 1 &&
options[:is_apocopated]
t([:ones, options[:gender]].join('.'))[number]
end

Expand All @@ -20,12 +21,9 @@ def twenties_with_ones(numbers, options = {})
end

def tens_with_ones(numbers, options = {})
ones_number = if options[:is_apocopated] && numbers[0] == 1
t(%i[ones apocopated].join('.'))
else
t([:ones, options[:gender]].join('.'))[numbers[0]]
end
[tens(numbers[1], alone: false), t(:union), ones_number].join(' ')
[tens(numbers[1], alone: false),
t(:union),
ones(numbers[0], options)].join(' ')
end

def hundreds(number, options = {})
Expand Down
6 changes: 6 additions & 0 deletions spec/numbers_and_words/integer/fixture_examples/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ to_words:
:gender: female
1: una
21: veintiuna
31: treinta y una
101: ciento una
900: novecientas
999: novecientas noventa y nueve
Expand All @@ -112,3 +113,8 @@ to_words:
31: treinta y un
100: cien
101: ciento un
female and apocopated form:
options:
:gender: female
:apocopated: true
901: novecientas un

0 comments on commit 3355822

Please sign in to comment.