Module: EacRailsUtils::FormatterHelper

Extended by:
ActiveSupport::Concern
Defined in:
app/helpers/eac_rails_utils/formatter_helper.rb

Instance Method Summary collapse

Instance Method Details

#brl_currency_to_float(currency) ⇒ Object


32
33
34
# File 'app/helpers/eac_rails_utils/formatter_helper.rb', line 32

def brl_currency_to_float(currency)
  currency.to_s.gsub(/[R$ .]/, '').tr(',', '.').to_f
end

#eac_number_to_percentage(float_value) ⇒ Object


28
29
30
# File 'app/helpers/eac_rails_utils/formatter_helper.rb', line 28

def eac_number_to_percentage(float_value)
  number_to_percentage(float_value * 100, precision: 0)
end

#format_cep(cep) ⇒ Object


36
37
38
# File 'app/helpers/eac_rails_utils/formatter_helper.rb', line 36

def format_cep(cep)
  "#{cep[0, 5]}-#{cep[5, 3]}"
end

#format_real(value) ⇒ Object


18
19
20
21
22
23
24
25
26
# File 'app/helpers/eac_rails_utils/formatter_helper.rb', line 18

def format_real(value)
  number_to_currency(
    value,
    unit: 'R$ ',
    separator: ',',
    delimiter: '.',
    raise: true
  )
end

#value_or_sign(value, sign = '-', &block) ⇒ Object


11
12
13
14
15
16
# File 'app/helpers/eac_rails_utils/formatter_helper.rb', line 11

def value_or_sign(value, sign = '-', &block)
  return sign if value.blank?
  return yield(value) if block

  value
end