Sha256: aa4c37a91f520e951c4f1b8bb66abc41c13a8cebce49a3343375fd16dd5edc37

Contents?: true

Size: 864 Bytes

Versions: 1

Compression:

Stored size: 864 Bytes

Contents

#
# Cities
#
class City
  include Mongoid::Document
  include Mongoid::Geospatial
  include Geopolitocracy

  field :zip,    type: String
  field :area,   type: Integer
  field :souls,  type: Integer
  field :geom,   type: Point,   spatial: true

  spatial_scope :geom

  attr_writer :x, :y, :z

  belongs_to :region
  belongs_to :nation
  has_many :hoods

  index name: 1

  scope :ordered, -> { order_by(name: 1) }

  validates :slug, presence: true, uniqueness: true
  validates :name, uniqueness: { scope: :nation_id }

  # scope :close_to, GeoHelper::CLOSE

  before_validation :set_defaults

  def set_defaults
    self.nation ||= region.try(:nation)
  end

  def abbr
    return unless region || nation
    region ? region.abbr : nation.abbr
  end

  def self.search(txt)
    where(slug: /#{txt}/i)
  end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
geopolitical-0.8.4 app/models/city.rb