Class: City

Inherits:
Object
  • Object
show all
Includes:
Geopolitocracy, Mongoid::Document, Mongoid::Geospatial
Defined in:
app/models/city.rb

Overview

Cities

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#x=(value) ⇒ Object (writeonly)

Sets the attribute x

Parameters:

  • value

    the value to set the attribute x to.



15
16
17
# File 'app/models/city.rb', line 15

def x=(value)
  @x = value
end

#y=(value) ⇒ Object (writeonly)

Sets the attribute y

Parameters:

  • value

    the value to set the attribute y to.



15
16
17
# File 'app/models/city.rb', line 15

def y=(value)
  @y = value
end

#z=(value) ⇒ Object (writeonly)

Sets the attribute z

Parameters:

  • value

    the value to set the attribute z to.



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

#phoneObject



49
50
51
# File 'app/models/city.rb', line 49

def phone
  self[:phone] || region.phone || nation.phone
end

#phonesObject



53
54
55
# File 'app/models/city.rb', line 53

def phones
  hoods.map(&:phone)
end

#postalObject



57
58
59
# File 'app/models/city.rb', line 57

def postal
  self[:postal] || region.postal || nation.postal
end

#postalsObject



61
62
63
# File 'app/models/city.rb', line 61

def postals
  hoods.map(&:postal)
end

#region_inside_nationObject



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_defaultsObject



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 || region.slug}"
  return unless City.where(slug: slug).first
  raise "Two cities with the same name in #{region}: '#{slug}'"
end

#to_sObject



84
85
86
# File 'app/models/city.rb', line 84

def to_s
  with_region
end

#with_nationObject



80
81
82
# File 'app/models/city.rb', line 80

def with_nation
  with_region + '/' + nation.abbr
end

#with_regionObject



75
76
77
78
# File 'app/models/city.rb', line 75

def with_region
  return name unless region
  "#{name}/#{region.abbr || region.name}"
end