Class: Place
- Inherits:
-
Object
- Object
- Place
- Includes:
- MongoMapper::Document
- Defined in:
- lib/oii_twitter_goodies/model/place.rb
Class Method Summary collapse
Class Method Details
.example ⇒ Object
20 21 22 |
# File 'lib/oii_twitter_goodies/model/place.rb', line 20 def self.example {"id"=>"99cdab25eddd6bce", "url"=>"http://api.twitter.com/1/geo/id/99cdab25eddd6bce.json", "place_type"=>"city", "name"=>"Amsterdam", "full_name"=>"Amsterdam, North Holland", "country_code"=>"NL", "country"=>"The Netherlands", "bounding_box"=>{"type"=>"Polygon", "coordinates"=>[[[4.7289, 52.278227], [5.079207, 52.278227], [5.079207, 52.431229], [4.7289, 52.431229]]]}, "attributes"=>{}} end |
.new_from_raw(place, tweet_id) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/oii_twitter_goodies/model/place.rb', line 24 def self.new_from_raw(place, tweet_id) return if place.nil? place = Hashie::Mash[place.attrs] obj = self.new obj.twitter_id = place["twitter_id"] obj.url = place["url"] obj.place_type = place["place_type"] obj.name = place["name"] obj.full_name = place["full_name"] obj.country_code = place["country_code"] obj.country = place["country"] bounding_box = BoundingBox.new_from_raw(place["bounding_box"].attrs, obj._id) if bounding_box obj.bounding_box = bounding_box end place["attributes"].each_pair do |key, value| place = PlaceAttribute.new_from_raw(key, value, obj._id) obj.place_attributes << place end obj.tweet_id = tweet_id obj.save! obj end |