class MasonellwoodCliAppTwo::CLI

Constants

EVERY_STATE

Attributes

state_info[RW]

Public Instance Methods

call() click to toggle source
# File lib/masonellwood_cli_app_two/cli.rb, line 6
def call
  greet_with_prompt
  set_up_instance_variable
  goodbye
end
display_citie_option() click to toggle source
# 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_weather() click to toggle source
# 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
goodbye() click to toggle source
# File lib/masonellwood_cli_app_two/cli.rb, line 71
def goodbye
  puts "See you tomorrow for more weather reports!"
end
greet_with_prompt() click to toggle source
# 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_variable() click to toggle source
# 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" || state == "States" || state == "STATES"
        EVERY_STATE.each_with_index do |state, index|
          index += 1
          puts "#{index}. #{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