Sha256: c710e357aa1b5e9a9639b531c7994fe31a681ca9d322db0050b3714ea18ddff2

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 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 countries
          Kernel.warn("Currencies#countries will be deprecated. Please use Currencies#for_code.")
          resource_countries.keys.map(&:to_s)
        end

        def currency_codes(locale = :en)
          resource(locale).keys.map { |c| c.to_s }
        end

        def for_country(country_name, locale = :en)
          Kernel.warn("Currencies#for_country will be deprecated. Please use Currencies#for_code.")
          for_code(resource_countries[country_name.to_sym][:code], locale) if resource_countries[country_name.to_sym]
        end

        def for_code(currency_code, locale = :en)
          currency_code = currency_code.to_sym
          data = resource(locale)[currency_code]
          { :currency => currency_code,
            :name => data[:one],
            :symbol => data[:symbol] } if data
        end

        private

        def resource_countries
          @resource_countries ||= TwitterCldr.get_resource(:shared, :currencies)
        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

3 entries across 3 versions & 1 rubygems

Version Path
twitter_cldr-2.0.2 lib/twitter_cldr/shared/currencies.rb
twitter_cldr-2.0.1 lib/twitter_cldr/shared/currencies.rb
twitter_cldr-2.0.0 lib/twitter_cldr/shared/currencies.rb