Method: WeatherPup::CLI#fetch_by_gps
- Defined in:
- lib/weatherpup/cli.rb
#fetch_by_gps ⇒ Object
fetch the current conditions via zip code input from the user
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/weatherpup/cli.rb', line 139 def fetch_by_gps #initialize my trigger variable valid_coordinates for my until loop valid_coordinates = nil #Clear my screen first to make things look nicer system "clear" #Ask user for the latitude and longitude until we get a valid input. puts "\nOk, Current Weather Conditions by GPS coordinates!".colorize(:light_blue) until valid_coordinates #Grab the Lat from the user puts "\nPlease enter in the ".colorize(:light_blue) + "latitude".colorize(:green).underline + " in decimal notation:".colorize(:light_blue) latitude = gets.chomp #Checking to see if the user wants out of this loop and back to the main menu before proceeding if latitude.downcase == "back" system "clear" break end #Grab the Longitude from the user puts "\nPlease enter in the ".colorize(:light_blue) + "longitude".colorize(:magenta).underline + " in decimal notation:".colorize(:light_blue) longitude = gets.chomp #Checking to see if the user wants out of this loop and back to the main menu if longitude.downcase == "back" system "clear" break end #Checking to see if the coordinates are valid using method #valid_coordinate_pair? valid_coordinates = self.valid_coordinate_pair?(latitude, longitude) # If the coordinates are valid, get and display the weather info. if valid_coordinates #Clear the screen to make it look nicer system "clear" #Do the actual work of getting the data from the API, processing it, and printing it to screen self.get_and_print_by_gps(latitude, longitude) #Next I wait for the user to type in "back" to return to the main menu self. #Once the user types back, clear the screen and break out of this until loop system "clear" break else puts <<~INVALID_GPS \n#{"Invalid coordinates detected!".colorize(:light_red)} (Type #{"back".colorize(:red)} to return to the main menu). INVALID_GPS end end end |