Class: WeatherByDcq::View

Inherits:
Object
  • Object
show all
Defined in:
lib/weather_by_dcq/view.rb

Defined Under Namespace

Classes: WeatherError

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#forecastObject

Returns the value of attribute forecast.



7
8
9
# File 'lib/weather_by_dcq/view.rb', line 7

def forecast
  @forecast
end

#locationObject

Returns the value of attribute location.



7
8
9
# File 'lib/weather_by_dcq/view.rb', line 7

def location
  @location
end

Instance Method Details



9
10
11
12
13
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
40
41
# File 'lib/weather_by_dcq/view.rb', line 9

def menu
  puts ''
  puts 'Please enter a city to retrieve a forecast (Format: City State):'
  input_location = gets.strip
  location = input_location.gsub(/[\W\d]/, '').downcase

  puts "You entered: #{location}".colorize(:blue) + ' Is this correct (Y/N)?'
  input_confirm = gets.strip.downcase
  if input_confirm == 'n'
    puts 'I am sorry, let us try again.'
    menu
  elsif input_confirm == 'y'
    system('cls') || system('clear')
    puts ''
    puts "Current Conditions for #{location}:".colorize(:blue)
    puts '====================================='
    WeatherByDcq::Forecast.display_curr_table(location)

    # Extended forecast List
    puts 'Extended forecast:'.colorize(:blue)
    puts '--------------------'
    WeatherByDcq::Forecast.display_forecast_list
    puts ''
    options_menu
  else
    begin
      raise WeatherError
    rescue WeatherError => e
      puts e.message
    end
    menu
  end
end

#options_menuObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/weather_by_dcq/view.rb', line 43

def options_menu
  puts ''
  puts 'Would you like additional details about any of the days listed?'.colorize(:blue)
  puts 'Please enter the corresponding number for your request, or any letter to EXIT: '.colorize(:blue)
  detail_input = gets.strip.to_i
  if detail_input.positive? && detail_input < 9
    system('cls') || system('clear')
    WeatherByDcq::Forecast.display_details(detail_input)
    options_menu

  elsif detail_input.negative? || detail_input > 8
    begin
      raise WeatherError
    rescue WeatherError => e
      puts e.message
    end
    options_menu
  else
    exit
  end
end