Class: Geonames::Models::City

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/geonames_local/models/postgis.rb

Overview

module Postgis

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xObject

Returns the value of attribute x.



6
7
8
# File 'lib/geonames_local/models/postgis.rb', line 6

def x
  @x
end

#yObject

Returns the value of attribute y.



6
7
8
# File 'lib/geonames_local/models/postgis.rb', line 6

def y
  @y
end

#zObject

Returns the value of attribute z.



6
7
8
# File 'lib/geonames_local/models/postgis.rb', line 6

def z
  @z
end

Instance Method Details

#abbrObject

validates_uniqueness_of :name, :scope => :region_id



15
16
17
# File 'lib/geonames_local/models/postgis.rb', line 15

def abbr
  region.try(:abbr) || nation.abbr
end

#geom=(val) ⇒ Object



19
20
21
22
23
24
# File 'lib/geonames_local/models/postgis.rb', line 19

def geom=(val)
  self[:geom] = case val
  when Array then Point.xy(*val)
  else val
  end
end

#validationObject

Instantiate self.geom as a Point



27
28
29
30
31
32
# File 'lib/geonames_local/models/postgis.rb', line 27

def validation
  self.nation ||= region.nation
  unless !@x || !@y || @x == '' || @y == ''
    self.geom = Point.from_x_y(@x.to_f, @y.to_f)
  end
end