Module: BrazilianUtils::NumberUtils
- Defined in:
- lib/brazilian-utils/number-utils.rb
Overview
Utilities for writing numbers in Brazilian Portuguese cardinal words
("por extenso"), e.g. 1235 becomes "mil duzentos e trinta e cinco".
Constant Summary collapse
- MAX_ABS_VALUE =
999_999_999_999_999- FEMININE_GENDERS =
%i[feminine feminino f].freeze
Class Method Summary collapse
-
.convert_to_words(value, options = {}) ⇒ String
Writes an integer in Brazilian Portuguese cardinal words.
Class Method Details
.convert_to_words(value, options = {}) ⇒ String
Writes an integer in Brazilian Portuguese cardinal words.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/brazilian-utils/number-utils.rb', line 26 def self.convert_to_words(value, = {}) return '' unless value.is_a?(Numeric) return '' if value.respond_to?(:finite?) && !value.finite? int_value = value.to_i return '' if int_value.abs > MAX_ABS_VALUE gender = ([:gender] || ['gender'] || :masculine).to_sym negative = int_value.negative? words = number_to_words(int_value.abs, gender) negative ? "menos #{words}" : words end |