Class: MasonellwoodCliAppTwo::CLI

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

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

#another_stateObject



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/masonellwood_cli_app_two/cli.rb', line 79

def another_state
  puts "would you like to check a different state? Type yes or no."
  input = nil
  input = gets.strip.downcase
  case input
  when "yes"
    set_up_instance_variable
  when "no"
    goodbye
  else
    puts "Please type yes or no"
  end
end

#callObject



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

def call
  greet_with_prompt
  set_up_instance_variable
  goodbye
end

#display_citie_optionObject



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

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
    citys = city.split(/ : /)
    puts "#{index}: #{citys[0]}"
  end
  display_city_weather
end

#display_city_weatherObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/masonellwood_cli_app_two/cli.rb', line 53

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

#goodbyeObject



93
94
95
# File 'lib/masonellwood_cli_app_two/cli.rb', line 93

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

#greet_with_promptObject



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

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

#set_up_instance_variableObject



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
# File 'lib/masonellwood_cli_app_two/cli.rb', line 15

def set_up_instance_variable
  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" ]
  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 every_state.include?(state) == false && state != "states" && 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