Class: Woefoo::GeoplanetPlace

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/woefoo/geoplanet_place.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build_ancestry_from_parent_ids!(parent_id = nil, ancestry = nil) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/woefoo/geoplanet_place.rb', line 50

def self.build_ancestry_from_parent_ids! parent_id = nil, ancestry = nil
  parent_id = parent_id || 0
  self.base_class.all(:conditions => {:parent_woeid => parent_id}).each do |node|
    node.without_ancestry_callbacks do
      node.update_attribute ancestry_column, ancestry
    end
    build_ancestry_from_parent_ids! node.id, if ancestry.nil? then "#{node.id}" else "#{ancestry}/#{node.id}" end
  end
end

Instance Method Details

#continentObject



28
29
30
# File 'lib/woefoo/geoplanet_place.rb', line 28

def continent
  self.ancestors.find(:first, :conditions => {:place_type => "Continent"})
end

#countryObject



24
25
26
# File 'lib/woefoo/geoplanet_place.rb', line 24

def country
  self.ancestors.find(:first, :conditions => {:place_type => "Country"})
end

#full_nameObject



32
33
34
35
36
37
38
39
40
# File 'lib/woefoo/geoplanet_place.rb', line 32

def full_name
  if !@full_name
    @full_name = self.name
    @full_name = "#{@full_name}, #{self.region.name}" if self.region
    @full_name = "#{@full_name}, #{self.country.name}" if self.country
  end

  return @full_name
end

#full_name_partsObject



42
43
44
45
46
47
48
# File 'lib/woefoo/geoplanet_place.rb', line 42

def full_name_parts
  ret = {:name => self.name}
  ret[:region_name] = self.region.name if self.region
  ret[:country_name] = self.country.name if self.country
  ret[:continent_name] = self.continent.name if self.continent
  return ret
end

#regionObject



20
21
22
# File 'lib/woefoo/geoplanet_place.rb', line 20

def region
  self.ancestors.find(:first, :conditions => {:place_type => "State"})
end

#townObject



16
17
18
# File 'lib/woefoo/geoplanet_place.rb', line 16

def town
  self.ancestors.find(:first, :conditions => {:place_type => "Town"})
end