<commit_before>require_relative '../config/environment'

# you don't need this if you have the require_all 'lib' line on the environment
# and you have the bundler gem properly installed.  This is here so I can learn how
# to use require statements in lieu of the bundler gem, in case for some reason I'm
# not using it.
require_relative 'weather_parameters'

class BoulderWeatherCheck
end
# This is the CLI Controller that encapsulates the business logic
# I sorta copied Avi's video on the subject; but now that I'm here, I don't
# see the value in the ::CLI vs. just putting all this in the BoulderWeatherCheck class
# directly instead.

# Apparently this is called a "namespace" and it's just good convention to use them even if
# the actual class outside the namespace does nothing at all but sit there.
class BoulderWeatherCheck::CLI
  attr_accessor :start_hour, :end_hour
  WEATHER_PARAMETERS = WeatherParameters.new

  def call
    program_use
    update_warning
    select_start_time
    select_end_time
    start_and_end_times_different
    run_program
    custom_or_default_weather_parameters
    is_the_weather_suitable
    option_to_see_problematic_weather_by_the_hour
    option_to_see_weather_by_the_hour
    option_to_continue
    good_bye
  end

  def program_use
    puts "Welcome to the Boulder Weather-Check Program!\n\n"
    puts <<-DOC.gsub /^\s*/, ''
      This program will tell you if the weather in
      Boulder Colorado is suitable for outdoor
      recreational activities during a timeframe
      you specify.
    DOC
    puts " \n"
    puts <<-DOC.gsub /^\s*/, ''
      I'm smart so you can be lazy! I will figure out
      if you want 'am' or 'pm' times; keep in mind that I
      can only predict the weather 11 hours out from now,
      so don't ask me for anything else or I'll crash on you.
    DOC
    puts "\nPress any key to continue"
    user_input = gets.chomp.downcase
    puts " \n"
  end

  def custom_or_default_weather_parameters
    puts "\nWhich weather settings would you prefer to use?"
    puts ""
    puts "    1.) Default weather settings"
    puts ""
    puts "    2.) Your own customized weather settings"
    puts "\nChoose 1 or 2"
    user_input = gets.chomp.downcase
    if user_input == "2"
      custom_weather_parameters
    else
      while user_input != "1"
        puts "Huh!?  type 1 or 2"
        user_input = gets.chomp.downcase
      end
      puts "you have chosen to use my default parameters."

      WEATHER_PARAMETERS.use_default_parameters
      puts "press any key to continue"
      user_input = gets.chomp.downcase
    end
  end

  def custom_weather_parameters

# Right now this method doesn't do anything and is a candidate for deletion
#    def min_max_values(input)
#      while input.to_i < -40 || input.to_i > 130
#        puts "\nWhoa that's crazy...please enter a value between -40 and 130"
#        input = gets.chomp.to_i
#        input
#      end
#    end

    puts "\nWhat is the maximum air temperature (°F) you're willing to go outside in?\n"

    user_input_1 = gets.chomp.to_i
      first_custom_input = valid_value(user_input_1, "-40", "110")
#     It seems I've successfully refactored this out with the valid_value method...testing continues.
#     while user_input_1.to_i < -40 || user_input_1.to_i > 110
#       puts "\nWhoa that's crazy...please enter a value between -40 and 110"
#       user_input_1 = gets.chomp.to_i
#     end

    puts "\nOK cool...what is the minimum air temperature (°F) you're willing to go out in?"

    user_input_2 = gets.chomp.to_i
      second_custom_input = valid_value(user_input_2, "-40", "110")
#     It seems I've successfully refactored this out with the valid_value method...testing continues.
#     while user_input_2.to_i < -40 || user_input_2.to_i > 110
#       puts "\nWhoa that's crazy...please enter a value between -40 and 110"
#       user_input_2 = gets.chomp.to_i
#     end

      while first_custom_input < second_custom_input
        puts "\nUh oh, you can't hava a minimum temperature that is higher than your maximum temperature; please enter a lower value"
          second_custom_input = gets.chomp.to_i
      end

      # OK so you need this instance of valid_value after the previous comparrison:
      # "first_custom_input < second_custom_input" because otherwise the program will
      # not check again to make sure the "second_custom_input" is in fact within proper range.
      second_custom_input = valid_value(second_custom_input, "-40", "110")

#     This code was just replaced with the valid_value statement right above...
#     ...so this code is slated for deletion after everything else is working 100%.
#      while user_input_2.to_i < -40 || user_input_2.to_i > 110
#        puts "\nWhoa that's crazy...please enter a value between -40 and 110"
#        user_input_2 = gets.chomp.to_i
#      end

    puts "\nNow tell me maximum percentage-chance of rain you're willing to tolerate?"
    user_input_3 = gets.chomp.to_i
      third_custom_input = valid_value(user_input_3, "0", "100")


#     while user_input_3.to_i < 0 || user_input_3.to_i > 100
#       puts "\nHuh? I don't get that answer...please enter a value between 0 and 100"
#       user_input_3 = gets.chomp.to_i
#     end

    puts "\nFinally, what is the maximum wind-speed (miles-per-hour) you're willing to tolerate?"
    user_input_4 = gets.chomp.to_i
      forth_custom_input = valid_value(user_input_4, "0", "200")


#     while user_input_4.to_i < 0 || user_input_4.to_i > 200
#       puts "\nHuh? I don't get that answer...please enter a value between 0 and 200"
#       user_input_4 = gets.chomp.to_i
#     end


    WEATHER_PARAMETERS.use_user_defined_parameters(first_custom_input, second_custom_input, third_custom_input, forth_custom_input)

    puts "\nCool, so here's where we stand:"
    puts "Maximum Temperature: #{WEATHER_PARAMETERS.hot_parameter}°"
    puts "Minimum Temperature: #{WEATHER_PARAMETERS.cold_parameter}°"
    puts "Maximum Chance of Precipitation: #{WEATHER_PARAMETERS.rain_parameter}%"
    puts "Maximum Allowable Windspeed: #{WEATHER_PARAMETERS.wind_parameter}mph"

    puts "\nPress any key to continue"
    user_input = gets.chomp
  end

  def select_start_time
    puts "\nEnter the first hour you would like to go out or type exit to leave the program"
    select_time
  end

  def select_end_time
    puts "\nEnter the final hour of your outdoor adventure or type exit to leave the program"
    select_time
  end

  def select_time
    input = gets.strip
    if input != "exit"
      valid_entry(input)
    else
      good_bye
      exit
    end
  end

  def start_and_end_times_different
    if self.start_hour == self.end_hour
      puts "\nOops, ther start & end times are exactly the same; this means I'll crash when I go to grab my data since I can only see 11 hours into the future from the current hour. \n"
      select_start_time
      select_end_time
    end
  end

  def valid_value(input, min_value, max_value)
    while input.to_i < min_value.to_i || input.to_i > max_value.to_i
      puts "\nWhoa that's crazy...please enter a value between #{min_value} and #{max_value}"
      input = gets.chomp.to_i
    end
    input
  end

  def valid_entry(input)
    x = input.to_i
    if x <= 0 || x >= 13
      puts "\nI'm sorry but I could not reconize that number, enter a number between 1 and 12"
      select_time
    else
      if self.start_hour == nil
        self.start_hour = x<commit_msg>Refactored valid_value method in CLI<commit_after>require_relative '../config/environment'

# you don't need this if you have the require_all 'lib' line on the environment
# and you have the bundler gem properly installed.  This is here so I can learn how
# to use require statements in lieu of the bundler gem, in case for some reason I'm
# not using it.
require_relative 'weather_parameters'

class BoulderWeatherCheck
end
# This is the CLI Controller that encapsulates the business logic
# I sorta copied Avi's video on the subject; but now that I'm here, I don't
# see the value in the ::CLI vs. just putting all this in the BoulderWeatherCheck class
# directly instead.

# Apparently this is called a "namespace" and it's just good convention to use them even if
# the actual class outside the namespace does nothing at all but sit there.
class BoulderWeatherCheck::CLI
  attr_accessor :start_hour, :end_hour
  WEATHER_PARAMETERS = WeatherParameters.new

  def call
    program_use
    update_warning
    select_start_time
    select_end_time
    start_and_end_times_different
    run_program
    custom_or_default_weather_parameters
    is_the_weather_suitable
    option_to_see_problematic_weather_by_the_hour
    option_to_see_weather_by_the_hour
    option_to_continue
    good_bye
  end

  def program_use
    puts "Welcome to the Boulder Weather-Check Program!\n\n"
    puts <<-DOC.gsub /^\s*/, ''
      This program will tell you if the weather in
      Boulder Colorado is suitable for outdoor
      recreational activities during a timeframe
      you specify.
    DOC
    puts " \n"
    puts <<-DOC.gsub /^\s*/, ''
      I'm smart so you can be lazy! I will figure out
      if you want 'am' or 'pm' times; keep in mind that I
      can only predict the weather 11 hours out from now,
      so don't ask me for anything else or I'll crash on you.
    DOC
    puts "\nPress any key to continue"
    user_input = gets.chomp.downcase
    puts " \n"
  end

  def custom_or_default_weather_parameters
    puts "\nWhich weather settings would you prefer to use?"
    puts ""
    puts "    1.) Default weather settings"
    puts ""
    puts "    2.) Your own customized weather settings"
    puts "\nChoose 1 or 2"
    user_input = gets.chomp.downcase
    if user_input == "2"
      custom_weather_parameters
    else
      while user_input != "1"
        puts "Huh!?  type 1 or 2"
        user_input = gets.chomp.downcase
      end
      puts "you have chosen to use my default parameters."

      WEATHER_PARAMETERS.use_default_parameters
      puts "press any key to continue"
      user_input = gets.chomp.downcase
    end
  end

  def custom_weather_parameters

# Right now this method doesn't do anything and is a candidate for deletion
#    def min_max_values(input)
#      while input.to_i < -40 || input.to_i > 130
#        puts "\nWhoa that's crazy...please enter a value between -40 and 130"
#        input = gets.chomp.to_i
#        input
#      end
#    end

    puts "\nWhat is the maximum air temperature (°F) you're willing to go outside in?\n"

    user_input_1 = gets.chomp.to_i
      first_custom_input = valid_value(user_input_1, "-40", "110")
#     It seems I've successfully refactored this out with the valid_value method...testing continues.
#     while user_input_1.to_i < -40 || user_input_1.to_i > 110
#       puts "\nWhoa that's crazy...please enter a value between -40 and 110"
#       user_input_1 = gets.chomp.to_i
#     end

    puts "\nOK cool...what is the minimum air temperature (°F) you're willing to go out in?"

    user_input_2 = gets.chomp.to_i
      second_custom_input = valid_value(user_input_2, "-40", "110")
#     It seems I've successfully refactored this out with the valid_value method...testing continues.
#     while user_input_2.to_i < -40 || user_input_2.to_i > 110
#       puts "\nWhoa that's crazy...please enter a value between -40 and 110"
#       user_input_2 = gets.chomp.to_i
#     end

      while first_custom_input < second_custom_input
        puts "\nUh oh, you can't hava a minimum temperature that is higher than your maximum temperature; please enter a lower value"
          second_custom_input = gets.chomp.to_i
      end

      # OK so you need this instance of valid_value after the previous comparrison:
      # "first_custom_input < second_custom_input" because otherwise the program will
      # not check again to make sure the "second_custom_input" is in fact within proper range.
      second_custom_input = valid_value(second_custom_input, "-40", "110")

#     This code was just replaced with the valid_value statement right above...
#     ...so this code is slated for deletion after everything else is working 100%.
#      while user_input_2.to_i < -40 || user_input_2.to_i > 110
#        puts "\nWhoa that's crazy...please enter a value between -40 and 110"
#        user_input_2 = gets.chomp.to_i
#      end

    puts "\nNow tell me maximum percentage-chance of rain you're willing to tolerate?"
    user_input_3 = gets.chomp.to_i
      third_custom_input = valid_value(user_input_3, "0", "100")


#     while user_input_3.to_i < 0 || user_input_3.to_i > 100
#       puts "\nHuh? I don't get that answer...please enter a value between 0 and 100"
#       user_input_3 = gets.chomp.to_i
#     end

    puts "\nFinally, what is the maximum wind-speed (miles-per-hour) you're willing to tolerate?"
    user_input_4 = gets.chomp.to_i
      forth_custom_input = valid_value(user_input_4, "0", "200")


#     while user_input_4.to_i < 0 || user_input_4.to_i > 200
#       puts "\nHuh? I don't get that answer...please enter a value between 0 and 200"
#       user_input_4 = gets.chomp.to_i
#     end


    WEATHER_PARAMETERS.use_user_defined_parameters(first_custom_input, second_custom_input, third_custom_input, forth_custom_input)

    puts "\nCool, so here's where we stand:"
    puts "Maximum Temperature: #{WEATHER_PARAMETERS.hot_parameter}°"
    puts "Minimum Temperature: #{WEATHER_PARAMETERS.cold_parameter}°"
    puts "Maximum Chance of Precipitation: #{WEATHER_PARAMETERS.rain_parameter}%"
    puts "Maximum Allowable Windspeed: #{WEATHER_PARAMETERS.wind_parameter}mph"

    puts "\nPress any key to continue"
    user_input = gets.chomp
  end

  def select_start_time
    puts "\nEnter the first hour you would like to go out or type exit to leave the program"
    select_time
  end

  def select_end_time
    puts "\nEnter the final hour of your outdoor adventure or type exit to leave the program"
    select_time
  end

  def select_time
    input = gets.strip
    if input != "exit"
      valid_entry(input)
    else
      good_bye
      exit
    end
  end

  def start_and_end_times_different
    if self.start_hour == self.end_hour
      puts "\nOops, ther start & end times are exactly the same; this means I'll crash when I go to grab my data since I can only see 11 hours into the future from the current hour. \n"
      select_start_time
      select_end_time
    end
  end

  def valid_value(input, min_value, max_value) 
    while !(input.match(/[a-zA-Z]/)) == false
      puts "Huh!?  I don't think that's an actual number...try one more time." 
      input = gets.chomp
    end 
  
    while input.to_i < min_value.to_i || input.to_i > max_value.to_i
      puts "\nWhoa that's crazy...please enter a value between #{min_value} and #{max_value}"
      input = gets.chomp
      output_due_to_outrageous_numbers = valid_value(input, min_value, max_value)
    end 
  

    if output_due_to_outrageous_numbers  == nil
      input.to_i
    else 
    output_due_to_outrageous_numbers 
    end 
  end

  def valid_entry(input)
    x = input.to_i
    if x <= 0 || x >= 13
      puts "\nI'm sorry but I could not reconize that number, enter a number between 1 and 12"
      select_time
    else
      if self.start_hour == nil
        self.start_hour = x
{'fraction_non_alphanumeric': 0.073520777611064, 'fraction_numerical': 0.016048013569052125, 'mean_word_length': 2.986996098829649, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5230201', 'n_tokens_mistral': 5069, 'n_tokens_neox': 4756, 'n_words': 1711}