Class: NumbersAndWords::Strategies::FiguresConverter::Languages::Es

Inherits:
Base
  • Object
show all
Includes:
Families::Latin
Defined in:
lib/numbers_and_words/strategies/figures_converter/languages/es.rb

Instance Attribute Summary

Attributes included from Families::Base

#current_capacity, #parent_figures

Attributes inherited from Base

#decorator, #figures, #language, #options, #translations

Instance Method Summary collapse

Methods included from Families::Base

#complex_number_to_words, #complex_tens, #hundreds_number_to_words, #save_parent_figures, #simple_number_to_words, #strings_logic, #words_in_capacity

Methods included from Families::Helpers

#translate

Methods inherited from Base

#initialize, #run

Constructor Details

This class inherits a constructor from NumbersAndWords::Strategies::FiguresConverter::Base

Instance Method Details

#capacity_iterationObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/numbers_and_words/strategies/figures_converter/languages/es.rb', line 8

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

  if 0 < @current_capacity
    # eg 1000000 should be "un millón" not "uno millón"
    #    501000 should be "quinientos un mil" not "quinientos uno mil"
    #    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) unless is_a_thousand? and is_a_one?
    }.compact
  end

  words + capacity_words
end

#hundredsObject



35
36
37
# File 'lib/numbers_and_words/strategies/figures_converter/languages/es.rb', line 35

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

#is_a_one?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/numbers_and_words/strategies/figures_converter/languages/es.rb', line 27

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

#is_a_thousand?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/numbers_and_words/strategies/figures_converter/languages/es.rb', line 31

def is_a_thousand?
  @current_capacity.odd?
end

#megs(capacity_words) ⇒ Object



39
40
41
# File 'lib/numbers_and_words/strategies/figures_converter/languages/es.rb', line 39

def megs capacity_words
  super({:is_one => capacity_words == [@translations.ones(1)]})
end