Sha256: 5c321d2d5d3ffb8ae3619cd66e02a269ec10f98ead64c847530e3fd7e8e7e82a

Contents?: true

Size: 982 Bytes

Versions: 2

Compression:

Stored size: 982 Bytes

Contents

require 'uncharted/country'

module Uncharted

  class Country

    def subdivisions
      @subdivisions ||= {}
    end

    def territories
      subdivisions[:territory] || []
    end

    def states
      subdivisions[:state] || []
    end

    def districts
      subdivisions[:district] || []
    end
    
    def self.subdivisions
      Territory.subdivisions
    end

  end

  class Territory

    attr_reader :abbr, :code, :country, :country_code, :name, :division

    def initialize(code, division, name)
      @code = code
      @division = division
      @name = name
      @country_code, @abbr = code.split('-')
      @country = Country.find(@country_code)
      Territory.subdivisions[code] = self
      @country.subdivisions[@division] ||= []
      @country.subdivisions[@division] << self
    end

    def to_s
      @abbr
    end
    
    def self.find(code)
      subdivisions[code]
    end

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

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
uncharted-0.0.6 lib/uncharted/territory.rb
uncharted-0.0.5 lib/uncharted/territory.rb