app/models/city.rb in geopolitical-0.8.8 vs app/models/city.rb in geopolitical-0.9.1
- old
+ new
@@ -4,17 +4,13 @@
class City
include Mongoid::Document
include Mongoid::Geospatial
include Geopolitocracy
- field :zip, type: String
field :area, type: Integer # m2 square area
- field :souls, type: Integer # Population
field :geom, type: Point, spatial: true
- alias_method :population, :souls
-
spatial_scope :geom
attr_writer :x, :y, :z
belongs_to :region
@@ -26,18 +22,26 @@
validates :name, uniqueness: { scope: :region_id }
validate :region_inside_nation
def region_inside_nation
return if !region || region.nation == nation
- errors.add(:region, "not inside Nation")
+ errors.add(:region, 'not inside Nation')
end
def set_defaults
self.nation ||= region.try(:nation)
return unless City.where(slug: slug).first
self.slug += "-#{region.abbr}"
return unless City.where(slug: slug).first
fail "Two cities with the same name in #{region}: '#{slug}'"
+ end
+
+ def phone
+ self[:phone] || region.phone || nation.phone
+ end
+
+ def postal
+ self[:postal] || region.postal || nation.postal
end
def ==(other)
other && slug == other.slug
end