Sha256: 09c1cb9b2f705e3e759c43ce97837e7234f59ab7c2ae16fa910f466023158a94

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require 'singleton'

class IsoCountryCodes
  class Code
    include Singleton

    def name
      self.class.name
    end

    def numeric
      self.class.numeric
    end

    def alpha2
      self.class.alpha2
    end

    def alpha3
      self.class.alpha3
    end

    def calling
      self.class.calling
    end

    def calling_code
      self.class.calling_code
    end

    def continent
      self.class.continent
    end
    
    def main_currency
      self.class.main_currency
    end

    def currency
      self.class.currency
    end

    def currencies
      self.class.currencies
    end

    class << self
      attr_accessor :name, :numeric, :alpha2, :alpha3, :calling, :continent, :main_currency
      attr_writer :currencies
      alias_method :currency, :main_currency
      alias_method :calling_code, :calling

      @@codes = []
      def inherited(code) #:nodoc:
        super
        @@codes << code.instance if self == IsoCountryCodes::Code
      end

      def all
        @@codes.uniq
      end

      def for_select(type = :alpha2)
        all.map { |country| [country.name, country.send(type)] }
      end

      def currencies
        if defined? @currencies
          return @currencies
        else
          return [@main_currency]
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
iso_country_codes-0.6.1 lib/iso_country_codes/code.rb