class NumbersAndWords::Strategies::FiguresConverter::Languages::PtBr

Public Instance Methods

capacity_iteration() click to toggle source
# File lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb, line 26
def capacity_iteration
  words = []
  capacity_words = words_in_capacity(current_capacity)
  words.push(megs) unless capacity_words.empty? || (capacity_words.empty? && figures[0] == 1)
  words + capacity_words
end
complex_number_to_words() click to toggle source
# File lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb, line 22
def complex_number_to_words
  super.compact
end
hundreds() click to toggle source
Calls superclass method
# File lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb, line 37
def hundreds
  super(internal_options.merge(is_hundred: hundred?, is_one_hundred: one_hundred?, gender:))
end
megs() click to toggle source
Calls superclass method
# File lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb, line 41
def megs
  super(internal_options.merge(number: @figures.number_in_capacity(@current_capacity),
                               is_opaque: opaque?,
                               is_without_connector: without_connector?,
                               is_with_comma: with_comma?))
end
ones() click to toggle source
Calls superclass method
# File lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb, line 33
def ones
  super(internal_options.merge(is_one_thousand: one_thousand?))
end
words() click to toggle source
# File lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb, line 18
def words
  super.strip
end
zero() click to toggle source
Calls superclass method
# File lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb, line 14
def zero
  super unless maybe_remove_zero
end

Private Instance Methods

gender() click to toggle source
# File lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb, line 58
def gender
  return options.gender.result || :male if maybe_ordinal

  if current_capacity&.positive? && figures[0] == 1
    :male
  else
    options.gender.result
  end
end
hundred?() click to toggle source
# File lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb, line 68
def hundred?
  figures[0].zero? && figures[1].zero? && simple_number_to_words.empty?
end
internal_options() click to toggle source
# File lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb, line 50
def internal_options
  { gender:, prefix: maybe_ordinal }
end
maybe_ordinal() click to toggle source
# File lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb, line 54
def maybe_ordinal
  @options.ordinal.result
end
maybe_remove_zero() click to toggle source
# File lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb, line 111
def maybe_remove_zero
  @options.remove_zero.result
end
one_hundred?() click to toggle source
# File lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb, line 72
def one_hundred?
  hundred? && figures[2] == 1
end
one_thousand?() click to toggle source
# File lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb, line 80
def one_thousand?
  current_capacity == 1 &&
    figures.ones == 1 &&
    figures.tens.nil? &&
    figures.hundreds.nil?
end
opaque?() click to toggle source
# File lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb, line 76
def opaque?
  figures.opaque? current_capacity
end
with_comma?() click to toggle source
# File lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb, line 97
def with_comma?
  return false unless @current_capacity > 1

  # if any lower capacity is single word, in portuguese only tens are single words
  number_under_capacity = figures.number_under_capacity(@current_capacity)
  return false if number_under_capacity < 20

  figures_under_capacity = figures.figures_array_under_capacity(@current_capacity)
  return false if figures_under_capacity.count(0) == (figures_under_capacity.size - 1)

  # else use comma
  true
end
without_connector?() click to toggle source
# File lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb, line 87
def without_connector?
  return false if with_comma?
  return true if figures.hundreds &&
                 (figures.tens_with_ones ||
                  figures.tens ||
                  figures.ones)

  false
end