require 'i18n' module Uncharted class Country attr_reader :alpha2, :alpha3, :name alias :code :alpha2 def initialize(alpha2, alpha3 = nil, name = nil) @alpha2 = alpha2 @alpha3 = alpha3 @name = name self.class.data[alpha2] = self end def inspect "#{@alpha2}: '#{@name}'" end def name(options = {}) I18n.t("countries.#{@alpha2}", {locale: options[:locale] || I18n.locale, default: @name}) 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