Sha256: ca0a06c4f9d7a2cd9fdbf9513c6657497b389fb9ca6ae236aa99e5b65f54c93f

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

require 'forwardable'

require 'carmen/world'
require 'carmen/region'
require 'carmen/querying'

module Carmen
  class Country < Region
    extend Querying
    extend SingleForwardable

    attr_reader :alpha_2_code
    attr_reader :alpha_3_code
    attr_reader :numeric_code

    def initialize(data={}, parent=nil)
      @alpha_2_code = data['alpha_2_code']
      @alpha_3_code = data['alpha_3_code']
      @numeric_code = data['numeric_code']
      super
    end

    def common_name
      Carmen.i18n_backend.translate(path('common_name'))
    end

    def official_name
      Carmen.i18n_backend.translate(path('official_name'))
    end

    def self.all
      World.instance.subregions
    end

    def self.query_collection
      all
    end

    def inspect
      %(<##{self.class} name="#{name}">)
    end

    def code
      alpha_2_code
    end

  private

    def self.attribute_to_search_for_code(code)
      code.to_s.size == 2 ? :alpha_2_code : :alpha_3_code
    end

    def subregion_directory
      alpha_2_code.downcase
    end

  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/carmen-1.0.2/lib/carmen/country.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/carmen-1.0.2/lib/carmen/country.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/carmen-1.0.2/lib/carmen/country.rb
carmen-1.0.2 lib/carmen/country.rb
carmens-1.0.1 lib/carmen/country.rb
carmen-1.0.1 lib/carmen/country.rb