Class: Location

Inherits:
Object
  • Object
show all
Includes:
MongoMapper::Document
Defined in:
lib/oii_twitter_goodies/model/location.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.coordinate_data_google(term) ⇒ Object



25
26
27
# File 'lib/oii_twitter_goodies/model/location.rb', line 25

def self.coordinate_data_google(term)
  return Google.locate(term).to_hash
end

.coordinate_data_yahoo(term) ⇒ Object



21
22
23
# File 'lib/oii_twitter_goodies/model/location.rb', line 21

def self.coordinate_data_yahoo(term)
  return Yahoo.locate(term)
end

.grab(term) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/oii_twitter_goodies/model/location.rb', line 8

def self.grab(term)
  term = term || ""
  if (loc = Location.first(:term => term.downcase))
    return loc
  else
    loc = Location.new(:term => term.downcase)
    loc.coordinate_data_yahoo = Location.coordinate_data_yahoo(term)
    loc.coordinate_data_google = Location.coordinate_data_google(term)
    loc.save!
    return loc
  end
end

Instance Method Details

#googleObject



29
30
31
32
33
34
35
36
# File 'lib/oii_twitter_goodies/model/location.rb', line 29

def google
  return self.coordinate_data_google if self.coordinate_data_google.nil?
  if self.coordinate_data_google["success"] && self.coordinate_data_google["success"] == true
    return {:lat => self.coordinate_data_google["lat"], :lng => self.coordinate_data_google["lng"]}
  else
    return nil
  end
end

#yahooObject



38
39
40
41
42
43
# File 'lib/oii_twitter_goodies/model/location.rb', line 38

def yahoo
  return self.coordinate_data_yahoo if self.coordinate_data_yahoo.nil? || self.coordinate_data_yahoo.empty?
  lat = self.coordinate_data_yahoo.split(",").first.to_f
  lng = self.coordinate_data_yahoo.split(",").last.to_f
  return {:lat => lat, :lng => lng}
end