Sha256: 9a8f4d361b846ecbcf2f1b3f12a570134b90e5575df47df08e6fb93aad159c7a

Contents?: true

Size: 893 Bytes

Versions: 2

Compression:

Stored size: 893 Bytes

Contents

#
# Nation/Country/Flag
#
class Nation
  include Mongoid::Document
  include Geopolitocracy

  field :_id, type: String, default: -> { abbr }

  field :gid,    type: Integer # geonames id
  field :tld,    type: String # Top level domain
  field :cash,   type: String # Currency prefix
  field :code3,  type: String # Iso 3166_3
  field :lang,   type: String # Official/main language
  field :langs,  type: Array  # All official languages

  alias currency cash
  alias iso_3166_3 code3

  validates :abbr, uniqueness: true, presence: true

  belongs_to :capital, inverse_of: :nation_capital, class_name: 'City'

  has_many :regions, dependent: :destroy
  has_many :cities,  dependent: :destroy

  index lang: 1

  def abbr=(txt)
    self[:abbr] = txt && txt.upcase
  end

  def ==(other)
    return unless other
    abbr == other.abbr
  end

  def <=>(other)
    name <=> other.name
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
geopolitical-1.0.5 app/models/nation.rb
geopolitical-1.0.3 app/models/nation.rb