Sha256: 92d3070f89b8d2dda95d213735258f544443a08ddb8dbaea84ca595eda56c06f

Contents?: true

Size: 584 Bytes

Versions: 24

Compression:

Stored size: 584 Bytes

Contents

module ISO3166
  class 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
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
countries-4.2.0 lib/countries/mongoid.rb
countries-4.1.3 lib/countries/mongoid.rb
countries-4.1.2 lib/countries/mongoid.rb
countries-4.1.1 lib/countries/mongoid.rb
countries-4.1.0 lib/countries/mongoid.rb
countries-4.0.1 lib/countries/mongoid.rb
countries-4.0.0 lib/countries/mongoid.rb
countries-3.1.0 lib/countries/mongoid.rb
countries-3.0.1 lib/countries/mongoid.rb
countries-3.0.0 lib/countries/mongoid.rb
countries-2.1.4 lib/countries/mongoid.rb
countries-2.1.3 lib/countries/mongoid.rb
countries-2.1.2 lib/countries/mongoid.rb
countries-2.1.1 lib/countries/mongoid.rb
countries-2.1.0 lib/countries/mongoid.rb
countries-2.0.8 lib/countries/mongoid.rb
countries-2.0.7 lib/countries/mongoid.rb
countries-2.0.6 lib/countries/mongoid.rb
countries-2.0.5 lib/countries/mongoid.rb
countries-2.0.4 lib/countries/mongoid.rb