Sha256: 40ad44a066a9c108b0e7f6e61531878a37a571c5233ebf59117104cecc2e4618

Contents?: true

Size: 570 Bytes

Versions: 7

Compression:

Stored size: 570 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
      else
        nil
      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

7 entries across 7 versions & 1 rubygems

Version Path
countries-1.1.0 lib/countries/mongoid.rb
countries-1.0.0 lib/countries/mongoid.rb
countries-0.11.5 lib/countries/mongoid.rb
countries-0.11.4 lib/countries/mongoid.rb
countries-0.11.3 lib/countries/mongoid.rb
countries-0.11.2 lib/countries/mongoid.rb
countries-0.11.1 lib/countries/mongoid.rb