Sha256: 6da4bb880b08546d7015e167a9c4b15d603ead91cd5ac5dc73474661fdaaa45a

Contents?: true

Size: 796 Bytes

Versions: 2

Compression:

Stored size: 796 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

2 entries across 2 versions & 1 rubygems

Version Path
eac_rails_utils-0.8.0 app/helpers/eac_rails_utils/formatter_helper.rb
eac_rails_utils-0.7.1 app/helpers/eac_rails_utils/formatter_helper.rb