Sha256: e765b8d7ccf6bb02838faa3e6aa1247845771060ef00279a002fc8e0c79a9c90

Contents?: true

Size: 1.32 KB

Versions: 40

Compression:

Stored size: 1.32 KB

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

module TwitterCldr
  module Shared
    module Currencies
      class << self
        def currency_codes(locale = :en)
          resource(locale).keys.map { |c| c.to_s }
        end

        def for_code(currency_code, locale = :en)
          currency_code = currency_code.to_sym
          data = resource(locale)[currency_code]
          symbol_data = iso_currency_symbols[currency_code]

          if data
            result = {
              currency:    currency_code,
              name:        data[:one],
              cldr_symbol: data[:symbol] || currency_code.to_s,
              symbol:      data[:symbol] || currency_code.to_s,
              code_points: (data[:symbol] || currency_code.to_s).unpack("U*")
            }

            result.merge!(symbol_data) if symbol_data
          end

          result
        end

        private

        # ISO 4217 to be precise
        def iso_currency_symbols
          @iso_currency_symbols ||= TwitterCldr.get_resource(:shared, :iso_currency_symbols)
        end

        def resource(locale)
          locale = locale.to_sym
          @resource ||= {}
          @resource[locale] ||= TwitterCldr.get_resource(:locales, locale, :currencies)[locale][:currencies]
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 2 rubygems

Version Path
twitter_cldr-6.11.2 lib/twitter_cldr/shared/currencies.rb
twitter_cldr-6.11.1 lib/twitter_cldr/shared/currencies.rb
twitter_cldr-6.11.0 lib/twitter_cldr/shared/currencies.rb
twitter_cldr-6.10.0 lib/twitter_cldr/shared/currencies.rb
twitter_cldr-6.9.0 lib/twitter_cldr/shared/currencies.rb
twitter_cldr-6.8.0 lib/twitter_cldr/shared/currencies.rb
twitter_cldr-6.7.0 lib/twitter_cldr/shared/currencies.rb
twitter_cldr-6.6.2 lib/twitter_cldr/shared/currencies.rb
twitter_cldr-6.6.1 lib/twitter_cldr/shared/currencies.rb
twitter_cldr-6.6.0 lib/twitter_cldr/shared/currencies.rb
twitter_cldr-6.5.0 lib/twitter_cldr/shared/currencies.rb
twitter_cldr-6.4.0 lib/twitter_cldr/shared/currencies.rb
twitter_cldr-6.3.0 lib/twitter_cldr/shared/currencies.rb
twitter_cldr-6.2.0 lib/twitter_cldr/shared/currencies.rb
twitter_cldr-6.1.0 lib/twitter_cldr/shared/currencies.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/lib/twitter_cldr/shared/currencies.rb
twitter_cldr-6.0.2 lib/twitter_cldr/shared/currencies.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/lib/twitter_cldr/shared/currencies.rb
twitter_cldr-6.0.1 lib/twitter_cldr/shared/currencies.rb
twitter_cldr-6.0.0 lib/twitter_cldr/shared/currencies.rb