Sha256: 57f5ce337f50c801ae6f831d39889944688797af4b4328a20af80dd7d27e53d4

Contents?: true

Size: 962 Bytes

Versions: 7

Compression:

Stored size: 962 Bytes

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 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, :main_currency
      attr_writer :currencies
      alias_method :currency, :main_currency

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

      def all
        @@codes.uniq
      end

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

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
alexrabarts-iso_country_codes-0.2.1 lib/iso_country_codes/code.rb
alexrabarts-iso_country_codes-0.2.2 lib/iso_country_codes/code.rb
holden-iso_country_codes-0.2.2 lib/iso_country_codes/code.rb
holden-iso_country_codes-0.2.3 lib/iso_country_codes/code.rb
holden-iso_country_codes-0.2.4 lib/iso_country_codes/code.rb
iso_country_codes-0.2.3 lib/iso_country_codes/code.rb
iso_country_codes-0.2.2 lib/iso_country_codes/code.rb