From 3ee433c3c4f48afb1513136939fb02122de4a904 Mon Sep 17 00:00:00 2001 From: jlduran Date: Mon, 21 Oct 2013 15:23:46 -0200 Subject: [PATCH] Add special case for one thousand in spanish --- .../figures_converter/languages/es.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/numbers_and_words/strategies/figures_converter/languages/es.rb b/lib/numbers_and_words/strategies/figures_converter/languages/es.rb index ea755dc9..f2b6fd03 100644 --- a/lib/numbers_and_words/strategies/figures_converter/languages/es.rb +++ b/lib/numbers_and_words/strategies/figures_converter/languages/es.rb @@ -11,18 +11,27 @@ def capacity_iteration words.push megs(capacity_words) unless capacity_words.empty? if 0 < @current_capacity - # eg 1000000 should be "un millon" not "uno millon" + # eg 1000000 should be "un millón" not "uno millón" # 501000 should be "quinientos un mil" not "quinientos uno mil" - # so we replace "uno" with "un" throughout + # 1000 should be "mil" not "uno mil" + # so we replace "uno" with "un" throughout or delete it if that is the case - capacity_words = capacity_words.map{|word| - word.gsub( @translations.ones(1), @translations.one ) - } + capacity_words = capacity_words.map { |word| + word.gsub(@translations.ones(1), @translations.one) unless is_a_thousand? and is_a_one? + }.compact end words + capacity_words end + def is_a_one? + [translations.ones(1)] == words_in_capacity(@current_capacity) + end + + def is_a_thousand? + FiguresArray::THOUSAND_CAPACITY == @current_capacity + end + def hundreds super({:is_hundred => (figures[1,2] == [0,1] && simple_number_to_words.empty?)}) end