Sha256: 4aedd5a6d9def98d77a06c312d86453f9256ce8f25a11ee6d61c75af4816aef6

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

# encoding: utf-8

module KingFormat
  # a little rewrite of the rails internal number helper with better:
  # - rounding
  # - detecting money symbol / money string
  # -
  module MoneyHelper

    # returns the keys from money symbols als Hash{array} for select options
    def money_selects
      money_symbols.keys.sort
    end

    # ==== Returns
    # Hash with currency as keys and formatting options as sub hash
    # { 'EUR' => {:unit=>'€', :format => '%n %u', :precision=> '2',:delimiter=>'.', :separator=>','},
    #   'USD' => {:unit=>'$'}
    def money_symbols
      @money_symbols ||= begin
        eur = {:format => '%n %u', :precision => '2',:delimiter => '.', :separator => ','}
        dol = {:format => '%u%n', :precision => '2',:delimiter => ',', :separator => '.'}
        {
        'EUR' => eur.merge(:unit=>'€'),
        'GBP' => dol.merge(:unit=>'£'),
        'JPY' => dol.merge(:unit=>'¥'),
        'USD' => dol.merge(:unit=>'$'),
        'AUD' => dol.merge(:unit=>'$'),
        'CAD' => dol.merge(:unit=>'$'),
        'HKD' => dol.merge(:unit=>'$'),
        'SGD' => dol.merge(:unit=>'$'),
        'AED' => nil,
        'BGN' => nil,
        'CZK' => nil,
        'DKK' => nil,
        'EEK' => nil,
        'HUF' => nil,
        'LTL' => nil,
        'LVL' => nil,
        'PLN' => eur.merge(:unit=>'zł', :delimiter => ' '),
        'RON' => nil,
        'SEK' => nil,
        'SKK' => nil,
        'CHF' => nil,
        'ISK' => nil,
        'NOK' => nil,
        'HRK' => nil,
        'RUB' => nil,
        'TRY' => nil,
        'BRL' => nil,
        'CNY' => nil,
        'IDR' => nil,
        'KRW' => nil,
        'MXN' => nil,
        'MYR' => nil,
        'NZD' => nil,
        'PHP' => nil,
        'THB' => nil,
        'ZAR' => dol.merge(:unit=>'R')
      }
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
king_views-1.2.0 king_format/lib/helpers/money_helper.rb