Class: Woefoo::GeoplanetPlace
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Woefoo::GeoplanetPlace
- Defined in:
- lib/woefoo/geoplanet_place.rb
Class Method Summary collapse
Instance Method Summary collapse
- #continent ⇒ Object
- #country ⇒ Object
- #full_name ⇒ Object
- #full_name_parts ⇒ Object
- #region ⇒ Object
- #town ⇒ Object
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
#continent ⇒ Object
28 29 30 |
# File 'lib/woefoo/geoplanet_place.rb', line 28 def continent self.ancestors.find(:first, :conditions => {:place_type => "Continent"}) end |
#country ⇒ Object
24 25 26 |
# File 'lib/woefoo/geoplanet_place.rb', line 24 def country self.ancestors.find(:first, :conditions => {:place_type => "Country"}) end |
#full_name ⇒ Object
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_parts ⇒ Object
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 |
#region ⇒ Object
20 21 22 |
# File 'lib/woefoo/geoplanet_place.rb', line 20 def region self.ancestors.find(:first, :conditions => {:place_type => "State"}) end |
#town ⇒ Object
16 17 18 |
# File 'lib/woefoo/geoplanet_place.rb', line 16 def town self.ancestors.find(:first, :conditions => {:place_type => "Town"}) end |