Module: EacRailsUtils::Helpers::Formatter
- Includes:
- ActionView::Helpers::NumberHelper
- Defined in:
- lib/eac_rails_utils/helpers/formatter.rb
Instance Method Summary collapse
- #brl_currency_to_float(currency) ⇒ Object
- #format_cep(cep) ⇒ Object
- #format_percentage(float_value) ⇒ Object
- #format_real(value) ⇒ Object
- #value_or_sign(value, sign = '-', &block) ⇒ Object
Instance Method Details
#brl_currency_to_float(currency) ⇒ Object
27 28 29 |
# File 'lib/eac_rails_utils/helpers/formatter.rb', line 27 def brl_currency_to_float(currency) currency.to_s.gsub(/[R$ .]/, '').tr(',', '.').to_f end |
#format_cep(cep) ⇒ Object
31 32 33 |
# File 'lib/eac_rails_utils/helpers/formatter.rb', line 31 def format_cep(cep) "#{cep[0, 5]}-#{cep[5, 3]}" end |
#format_percentage(float_value) ⇒ Object
23 24 25 |
# File 'lib/eac_rails_utils/helpers/formatter.rb', line 23 def format_percentage(float_value) number_to_percentage(float_value * 100, precision: 0) end |
#format_real(value) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/eac_rails_utils/helpers/formatter.rb', line 13 def format_real(value) number_to_currency( value, unit: 'R$ ', separator: ',', delimiter: '.', raise: true ) end |
#value_or_sign(value, sign = '-', &block) ⇒ Object
7 8 9 10 11 |
# File 'lib/eac_rails_utils/helpers/formatter.rb', line 7 def value_or_sign(value, sign = '-', &block) return sign if value.blank? return yield(value) if block value end |