lib/uncharted/country.rb in uncharted-0.0.8 vs lib/uncharted/country.rb in uncharted-0.0.9
- old
+ new
@@ -1,18 +1,29 @@
+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
@@ -35,9 +46,9 @@
end
def self.data
@data ||= {}
end
-
+
end
end
\ No newline at end of file