Sha256: 92974a7fe36f02d7fc8daa42327b0d41ac897182403ca452ff4946fa49a0ad60

Contents?: true

Size: 623 Bytes

Versions: 1

Compression:

Stored size: 623 Bytes

Contents

module Uncharted

  class Country

    attr_reader :alpha2, :alpha3, :name

    def initialize(alpha2, alpha3 = nil, name = nil)
      @alpha2 = alpha2
      @alpha3 = alpha3
      @name   = name
      self.class.data[alpha2] = self
    end

    def to_s
      @alpha2
    end

    def self.count
      countries.count
    end

    def self.find(objects)
      case objects
      when Array
        objects.collect {|c| data[c]}
      when Country
        objects
      else
        data[objects]
      end
    end

    def self.countries
      @data.values
    end

    def self.data
      @data ||= {}
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
uncharted-0.0.8 lib/uncharted/country.rb