Method: WeatherPup::CLI#fetch_previous

Defined in:
lib/weatherpup/cli.rb

#fetch_previousObject



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/weatherpup/cli.rb', line 222

def fetch_previous
   #Clear the screen to make it look nicer. 
   system "clear"

   #first check to see if there have been any previous checks -- if the array is blank, tell the user that there isn't anything to show.  Otherwise, print out a list of each WeatherConditions instance with details for the user pick from. 
   if WeatherPup::WeatherConditions.all == []
      system "clear"
      puts "\nThere are no previous fetches to display!".colorize(:cyan)
      self.return_to_main_menu_prompt
      system "clear"
   else
      #puts a blank line to give some headroom when displaying
      puts "\n"
      
      #ask the WeatherConditions class to print out a list of all its instances
      WeatherPup::WeatherConditions.list_all_previous

      #set my valid input range between 1 instance and however many instances of WeatherConditions there are in WeatherConditions @@all array.
      valid_input_range = 1..WeatherPup::WeatherConditions.all.length
      
      #Initialize my trigger to exit my until loop
      valid_input = nil
      
      #Until the user gives me a valid input, keep asking for a vaild input & give them the option to go back to the main menu.  If they do give me valid input, then go display that historic WeatherConditions object.
      until valid_input
         puts "            \\nPlease type in the \#{\"number\".colorize(:cyan)} of the previous fetch you would like to view\n            or type \#{\"back\".colorize(:red)} to return to the main menu.\n         USER_PROMPT\n         \n         #get the input fro mthe user\n         user_selection = gets.chomp.downcase\n\n         if user_selection == \"back\"\n            system \"clear\"\n            break\n         end\n\n         #convert my user input to an integer so that I can check to see if its in the valid range. \n         user_integer = user_selection.to_i\n         valid_input = valid_input_range.member?(user_integer)\n\n         #If it is in the valid range, go and print out the selected WeatherConditions objects info again.  Otherwise, keep asking for valid input and tell them how to go back. \n         if valid_input \n            selected_wc_obj = WeatherPup::WeatherConditions.all[user_integer - 1]\n            type = selected_wc_obj.current_conditions_means\n\n            case type \n            when \"Zip Code\"\n               system \"clear\"\n               selected_wc_obj.print_zip_conditions\n               self.return_to_main_menu_prompt\n               system \"clear\"\n               break\n            when \"GPS Coordinates\"\n               system \"clear\"\n               selected_wc_obj.print_gps_conditions\n               self.return_to_main_menu_prompt\n               system \"clear\"\n               break\n            end\n         else\n            puts \"\\n\#{\"Invalid selection.\".colorize(:light_red)} Please try again or type \#{\"back\".colorize(:red)} to return to the main menu.\"\n         end\n      end\n   end\nend\n"