Class: MasonellwoodCliAppTwo::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/masonellwood_cli_app_two/cli.rb

Constant Summary collapse

EVERY_STATE =
["alabama", "alaska", "arizona", "arkansas", "california", "colorado", "connecticut", "delaware", "florida", "georgia", "hawaii", "idaho", "illinois", "indiana", "iowa", "kansas", "kentucky", "louisiana", "maine", "maryland", "massachusetts", "michigan", "minnesota", "mississippi", "missouri", "montana", "nebraska", "nevada", "new hampshire", "new jersey", "new mexico", "new york", "north carolina", "north dakota", "ohio", "oklahoma", "oregon", "pennsylvania", "rhode island",
"south carolina", "south dakota", "tennessee", "texas", "utah", "vermont", "virginia", "washington", "west virginia", "wisconsin", "wyoming" ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#state_infoObject

Returns the value of attribute state_info.



3
4
5
# File 'lib/masonellwood_cli_app_two/cli.rb', line 3

def state_info
  @state_info
end

Instance Method Details

#callObject



6
7
8
9
10
# File 'lib/masonellwood_cli_app_two/cli.rb', line 6

def call
  greet_with_prompt
  set_up_instance_variable
  goodbye
end

#display_citie_optionObject



41
42
43
44
45
46
47
48
49
# File 'lib/masonellwood_cli_app_two/cli.rb', line 41

def display_citie_option
  puts "Awesome! It looks like you are interested in #{@state_info.state.capitalize}!"
  puts "Here are all of the cities in #{@state_info.state.capitalize}!"
  @state_info.cities.each_with_index.each do |city, index|
    index += 1
    puts "#{index}: #{city.name}"
  end
  display_city_weather
end

#display_city_weatherObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/masonellwood_cli_app_two/cli.rb', line 51

def display_city_weather
  puts "Enter the number of the city you want to view"
  input = nil
  while input != "exit"
    input = gets.strip.downcase
    if input == "cities"
      @state_info.cities.each_with_index.each do |city, index|
      index += 1
      puts "#{index}: #{city.name}"
    end
      puts "Now type the name of the city you want to know the weather of."
    elsif input.to_i.between?(1, @state_info.cities.size)
      city = @state_info.cities[input.to_i - 1]
      @state_info.city_weather(city)
    elsif input != "exit"
      puts "Please type a valid city, or type exit."
    end
  end
end

#goodbyeObject



71
72
73
# File 'lib/masonellwood_cli_app_two/cli.rb', line 71

def goodbye
  puts "See you tomorrow for more weather reports!"
end

#greet_with_promptObject



12
13
14
# File 'lib/masonellwood_cli_app_two/cli.rb', line 12

def greet_with_prompt
  puts "Welcome to your local Weather Channel!"
end

#set_up_instance_variableObject



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/masonellwood_cli_app_two/cli.rb', line 16

def set_up_instance_variable
  puts "Please type your State of interest."
  puts "If you forgot how to spell some of the state names, just type states."
  puts "If you don't care about the weather today, just type exit."
  state = nil
  while state != "exit"
    state = gets.strip.downcase
      if EVERY_STATE.include?(state)
        @state_info = MasonellwoodCliAppTwo::StateScraper.new(state)
        @state_info.scrape_cities
        display_citie_option
        puts "Are you sure you don't want to check the weather of a different state?"
        puts "Like before: type States, the State name, or simply type exit."
      elsif state == "states"
        every_state.each_with_index do |the_state, index|
          index += 1
          puts "#{index}. #{the_state.capitalize}"
        end
        puts "Here are all the valid States, which one would you like to know the weather?"
      elsif state != "exit"
        puts "Not sure what you want bud. Please type exit to quit. Or see the valid states by typing states."
      end
  end
end