Class: WeatherFetch::CLI
- Inherits:
-
Thor
- Object
- Thor
- WeatherFetch::CLI
- Defined in:
- lib/weatherfetch/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.exit_on_failure? ⇒ Boolean
9 10 11 |
# File 'lib/weatherfetch/cli.rb', line 9 def self.exit_on_failure? true end |
Instance Method Details
#current(city) ⇒ Object
14 15 16 17 18 |
# File 'lib/weatherfetch/cli.rb', line 14 def current(city) = { query: { q: city, appid: 'c8d7f5fd25b8914cc543ed45e6a40bba' } } r = HTTParty.get('http://api.openweathermap.org/data/2.5/weather', ) puts r end |
#daily(city) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/weatherfetch/cli.rb', line 44 def daily(city) response = fetch_city_data(city, 'daily') rows = response['daily'].map do |day| [ Rainbow(Time.at(day['dt']).strftime('%m/%d')).darkolivegreen, Rainbow("#{day['temp']['morn']}°F").darkolivegreen, Rainbow("#{day['temp']['day']}°F").darkolivegreen, Rainbow("#{day['temp']['eve']}°F").darkolivegreen, Rainbow("#{day['temp']['night']}°F").darkolivegreen, Rainbow(day['weather'][0]['description'].capitalize).darkolivegreen, Rainbow("#{day['humidity']}%").darkolivegreen ] end table = Terminal::Table.new do |t| t.headings = create_headings(['Date', 'Morning', 'Afternoon', 'Evening', 'Night', 'Conditions', 'Humidity']) t.rows = rows t.title = Rainbow(city.capitalize).cornflower t.style = { all_separators: :true } end puts table end |
#hourly(city) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/weatherfetch/cli.rb', line 21 def hourly(city) response = fetch_city_data(city, 'hourly') rows = response['hourly'].map do |hour| [ Rainbow(Time.at(hour['dt']).strftime('%m/%d %I %p')).darkolivegreen, Rainbow("#{hour['temp']}°F").darkolivegreen, Rainbow("#{hour['feels_like']}°F").darkolivegreen, Rainbow(hour['weather'][0]['description'].capitalize).darkolivegreen, Rainbow("#{hour['humidity']}%").darkolivegreen ] end table = Terminal::Table.new( headings: create_headings(['Hour', 'Actual', 'Feels Like', 'Conditions', 'Humidity']), rows: rows, title: Rainbow(city.capitalize).cornflower ) puts table end |