Sha256: 040df034494b1021746fd465f1aeb2ee6ec5927b6958080788336bdcfd132725

Contents?: true

Size: 547 Bytes

Versions: 9

Compression:

Stored size: 547 Bytes

Contents

module ISO3166; end

class ISO3166::Country
  def mongoize
    ISO3166::Country.mongoize(self)
  end

  class << self
    def mongoize(country)
      if country.is_a?(self) && !country.data.nil?
        country.alpha2
      elsif send(:valid_alpha2?, country)
        new(country).alpha2
      end
    end

    def demongoize(alpha2)
      new(alpha2)
    end

    def evolve(country)
      mongoize(country)
    end

    private

    def valid_alpha2?(country)
      country.is_a?(String) && !ISO3166::Country.new(country).nil?
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
countries-2.0.0.rc lib/countries/mongoid.rb
countries-2.0.0.pre.4 lib/countries/mongoid.rb
countries-2.0.0.pre.3 lib/countries/mongoid.rb
countries-2.0.0.pre.2 lib/countries/mongoid.rb
countries-1.2.5 lib/countries/mongoid.rb
countries-2.0.0.pre lib/countries/mongoid.rb
countries-1.2.4 lib/countries/mongoid.rb
countries-1.2.2 lib/countries/mongoid.rb
countries-1.2.1 lib/countries/mongoid.rb