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
#daily(location) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/weatherfetch/cli.rb', line 37 def daily(location) response = fetch_location_data(location, 'daily') rows = response['daily'].map do |day| [ Rainbow(Time.at(day['dt']).strftime('%m/%d')).darkolivegreen, Rainbow("#{day['temp']['min']}°F").darkolivegreen, Rainbow("#{day['temp']['max']}°F").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', 'Min', 'Max', 'Morning', 'Afternoon', 'Evening', 'Night', 'Conditions', 'Humidity']) t.rows = rows t.title = "#{Rainbow(get_title).cornflower}" t.style = { all_separators: :true } end puts table end |
#hourly(location) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/weatherfetch/cli.rb', line 14 def hourly(location) response = fetch_location_data(location, '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(get_title).cornflower}" ) puts table end |