Class: City
- Inherits:
-
Object
- Object
- City
- Includes:
- Geopolitocracy, Mongoid::Document, Mongoid::Geospatial
- Defined in:
- app/models/city.rb
Overview
Cities
Instance Attribute Summary collapse
-
#x ⇒ Object
writeonly
Sets the attribute x.
-
#y ⇒ Object
writeonly
Sets the attribute y.
-
#z ⇒ Object
writeonly
Sets the attribute z.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #phone ⇒ Object
- #phones ⇒ Object
- #postal ⇒ Object
- #postals ⇒ Object
- #region_inside_nation ⇒ Object
- #set_defaults ⇒ Object
- #to_s ⇒ Object
- #with_nation ⇒ Object
- #with_region ⇒ Object
Methods included from Geopolitocracy
Instance Attribute Details
#x=(value) ⇒ Object (writeonly)
Sets the attribute x
15 16 17 |
# File 'app/models/city.rb', line 15 def x=(value) @x = value end |
#y=(value) ⇒ Object (writeonly)
Sets the attribute y
15 16 17 |
# File 'app/models/city.rb', line 15 def y=(value) @y = value end |
#z=(value) ⇒ Object (writeonly)
Sets the attribute z
15 16 17 |
# File 'app/models/city.rb', line 15 def z=(value) @z = value end |
Instance Method Details
#<=>(other) ⇒ Object
70 71 72 73 |
# File 'app/models/city.rb', line 70 def <=>(other) return unless other.is_a?(City) slug <=> other.slug end |
#==(other) ⇒ Object
65 66 67 68 |
# File 'app/models/city.rb', line 65 def ==(other) return unless other.is_a?(City) other && slug == other.slug end |
#phone ⇒ Object
49 50 51 |
# File 'app/models/city.rb', line 49 def phone self[:phone] || region.phone || nation.phone end |
#phones ⇒ Object
53 54 55 |
# File 'app/models/city.rb', line 53 def phones hoods.map(&:phone) end |
#postal ⇒ Object
57 58 59 |
# File 'app/models/city.rb', line 57 def postal self[:postal] || region.postal || nation.postal end |
#postals ⇒ Object
61 62 63 |
# File 'app/models/city.rb', line 61 def postals hoods.map(&:postal) end |
#region_inside_nation ⇒ Object
36 37 38 39 |
# File 'app/models/city.rb', line 36 def region_inside_nation return if !region || region.nation == nation errors.add(:region, 'not inside Nation') end |
#set_defaults ⇒ Object
41 42 43 44 45 46 47 |
# File 'app/models/city.rb', line 41 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 |
#to_s ⇒ Object
84 85 86 |
# File 'app/models/city.rb', line 84 def to_s with_region end |
#with_nation ⇒ Object
80 81 82 |
# File 'app/models/city.rb', line 80 def with_nation with_region + '/' + nation.abbr end |
#with_region ⇒ Object
75 76 77 78 |
# File 'app/models/city.rb', line 75 def with_region return name unless region "#{name}/#{region.abbr || region.name}" end |