Sha256: 6633c2d8a465c1e408c796524ce8cf24d4171b465317b02347dd925ac1a14efc

Contents?: true

Size: 798 Bytes

Versions: 45

Compression:

Stored size: 798 Bytes

Contents

# frozen_string_literal: true

module EacRailsUtils
  module FormatterHelper
    extend ::ActiveSupport::Concern

    included do
      include ActionView::Helpers::NumberHelper
    end

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

      value
    end

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

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

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

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

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
eac_rails_utils-0.25.0 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.24.0 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.23.4 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.23.3 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.23.2 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.23.1 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.23.0 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.22.3 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.22.2 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.22.1 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.22.0 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.21.0 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.20.0 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.19.0 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.18.0 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.17.2 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.17.1 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.17.0 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.16.0 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.15.2 app/helpers/eac_rails_utils/formatter_helper.rb