Class: Fillmore
- Inherits:
-
Object
- Object
- Fillmore
- Defined in:
- lib/fillmore.rb
Constant Summary collapse
- API_URL =
'http://api.openweathermap.org/data/2.5/weather'
Instance Method Summary collapse
Instance Method Details
#fetch(location) ⇒ Object
8 9 10 11 12 |
# File 'lib/fillmore.rb', line 8 def fetch(location) response = HTTParty.get "#{API_URL}?q=#{URI.escape(location)}" # binding.pry JSON.parse response.body end |
#format(obj) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fillmore.rb', line 14 def format(obj) outcome = "#{obj['name']}" # binding.pry if !obj['sys'].nil? country = obj['sys']['country'] if !country.nil? outcome += " (#{country})" end outcome += "\n #{obj['weather'].first['main']}" description = obj['weather'].first['description'] if !description.nil? outcome += " - #{description}" end temp = obj['main']['temp'] celsius = temp.to_f - 273.15 fahrenheit = celsius * 1.8 + 32 outcome += "\n #{celsius.to_i}°C / #{fahrenheit.to_i}°F" outcome end end |
#run(location) ⇒ Object
41 42 43 |
# File 'lib/fillmore.rb', line 41 def run(location) puts format(fetch(location)) end |