Class: NumbersAndWords::Translations::PtBr

Inherits:
Base
  • Object
show all
Includes:
Extensions::FractionSignificance, Families::Latin
Defined in:
lib/numbers_and_words/translations/pt-BR.rb

Constant Summary

Constants inherited from Base

Base::I18N_NAMESPACE

Instance Method Summary collapse

Methods included from Extensions::FractionSignificance

#micro

Methods included from Families::Base

#mega, #union, #union_separator

Methods inherited from Base

#t

Instance Method Details

#hundreds(number, options = {}) ⇒ Object



39
40
41
42
43
44
# File 'lib/numbers_and_words/translations/pt-BR.rb', line 39

def hundreds(number, options = {})
  return t(:one_hundred) if options[:is_one_hundred] && !(ordinal? options)
  translated = t([options[:prefix], :hundreds, options[:gender]].join('.'))[number - 1]
  return translated if ordinal? options
  options[:is_hundred] ? translated : translated + " #{union}"
end

#integral(number, _options = {}) ⇒ Object



7
8
9
# File 'lib/numbers_and_words/translations/pt-BR.rb', line 7

def integral(number, _options = {})
  t(:integral, count: number)
end

#megs(capacity, options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/numbers_and_words/translations/pt-BR.rb', line 46

def megs(capacity, options = {})
  return t([options[:prefix], :mega, options[:gender]].join('.'))[capacity] if ordinal? options

  options[:is_one] = false if options[:is_one].nil?
  connector = " #{union}"
  connector = ',' if options[:is_with_comma]
  suffix = options[:is_opaque] ? '' : connector
  suffix = options[:is_without_connector] ? '' : suffix
  (options[:is_one] ? t(:mega)[capacity] : t(:megas)[capacity]) + suffix
end

#micro_prefix(capacity, number) ⇒ Object



63
64
65
66
67
68
# File 'lib/numbers_and_words/translations/pt-BR.rb', line 63

def micro_prefix(capacity, number)
  case capacity
  when 2 then t('micro_prefix.hundreds', count: number)
  when 1 then t('micro_prefix.tens', count: number)
  end
end

#micros(capacity, number, separator = t('micro_prefix.separator')) ⇒ Object



57
58
59
60
61
# File 'lib/numbers_and_words/translations/pt-BR.rb', line 57

def micros(capacity, number, separator = t('micro_prefix.separator'))
  micro, prefix = capacity
  micros = number ? t(micro(micro), count: number) : micro(micro)
  [micro_prefix(prefix, number), micros].compact.join(" #{separator} ")
end

#ones(number, options = {}) ⇒ Object



15
16
17
18
# File 'lib/numbers_and_words/translations/pt-BR.rb', line 15

def ones(number, options = {})
  return if options[:is_one_thousand]
  t([options[:prefix], :ones, options[:gender]].join('.'))[number]
end

#teens(number, options = {}) ⇒ Object



28
29
30
31
# File 'lib/numbers_and_words/translations/pt-BR.rb', line 28

def teens(number, options = {})
  return [tens(1, options), ' ', ones(number[0], options)].join if ordinal? options
  super(number, options)
end

#tens(number, options = {}) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/numbers_and_words/translations/pt-BR.rb', line 20

def tens(number, options = {})
  options[:alone] = true if options[:alone].nil?
  path = [options[:prefix], :tens]
  path.push(options[:gender]) if ordinal? options
  translated = t(path.join('.'))[number]
  options[:alone] ? translated : "#{union} " + translated
end

#tens_with_ones(numbers, options = {}) ⇒ Object



33
34
35
36
37
# File 'lib/numbers_and_words/translations/pt-BR.rb', line 33

def tens_with_ones(numbers, options = {})
  connector = ' '
  connector = " #{union} " unless ordinal? options
  [tens(numbers[1], options), connector, ones(numbers[0], options)].join
end

#zero(options = {}) ⇒ Object



11
12
13
# File 'lib/numbers_and_words/translations/pt-BR.rb', line 11

def zero(options = {})
  t([options[:prefix], :ones, :male].join('.'))[0]
end