Class: PlantScraper::CLI
- Inherits:
-
Object
- Object
- PlantScraper::CLI
- Defined in:
- lib/plant_info_scraper/cli.rb
Instance Method Summary collapse
- #exit ⇒ Object
- #height_filter ⇒ Object
- #menu(zip) ⇒ Object
- #plant_type_filter ⇒ Object
- #start ⇒ Object
- #sun_filter ⇒ Object
- #zip_code? ⇒ Boolean
Instance Method Details
#exit ⇒ Object
96 97 98 |
# File 'lib/plant_info_scraper/cli.rb', line 96 def exit puts "Thanks for using The Amazing but Unofficial Plant Scrapper!" end |
#height_filter ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/plant_info_scraper/cli.rb', line 124 def height_filter print "For Height, Enter \'" + "A".green + "\' for Any, \'" + "XS".green + "\' for less than 6 inches, \'" + "SM".green + "\' for 6 - 12 inches, \'" + "MD".green + "\' for 1 - 3 feet , \'" + "LG".green + "\' for 3 - 8 feet, \'" + "XL".green + "\' for 8 - 20 feet, or \'" + "XXL".green + "\' for over 20 feet. Only choose One: " height_entry = gets.chomp.upcase #checking that the height filter is an appropriate entry and is only of 7 values filterable if height_entry.length > 3 || !(["A", "XS", "SM", "MD", "LG", "XL", "XXL"].include?(height_entry)) puts height_entry puts "Your Entry was Incorrect Please Re-Enter Sun Type" height_filter else #Converting the height filter to a URL appropriate value case height_entry when "A" height_entry = "" when "XS" height_entry = "0-6" when "SM" height_entry = "6-12" when "MD" height_entry = "1-3" when "LG" height_entry = "3-8" when "XL" height_entry = "8-20" when "XXL" height_entry = "20" end end height_entry end |
#menu(zip) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/plant_info_scraper/cli.rb', line 39 def (zip) if PlantScraper::Plant.all.size > 0 puts " __".green puts " _ / /|".green puts " | \\\ \\/_/".green puts " \\_\\| / __ ".green puts " \\/_/__\\ ".green + ".-=='/~\\'".red puts " ____,__/__,_____,______)".green + "/ /{~}}}".red puts " -,------,----,-----,---,".green + "\\'-' {{~}}".red puts " '-==.\\}/".red print "\n\n" puts "##############################-- PLANTS FOR #{zip} --##############################" #binding.pry PlantScraper::Plant.all.each.with_index(1) { |plant, i| puts "#{i}. #{plant.name.strip}"} print "\n\n" print "Enter the number of the plant to see its details: " #", #or \'" + "N".green + "\' " input = gets.chomp if input.to_i > PlantScraper::Plant.all.size puts "Entry was incorrect press any key to try again".red (zip) if gets.chomp else plant = PlantScraper::Plant.all[input.to_i-1] print "\n\n" puts "Plant Name: #{plant.name}" puts "Light Type(s): #{plant.light}" puts "Height Range: #{plant.height}" puts "Growth Zones: #{plant.zones}" puts "Plant Type(s): #{plant.type}" puts "Summary: #{plant.summary}" print "\n" print "I hope you found this informative. To return to your results enter \'" + "R".green + "\', to start a new search enter \'" + "N".green + "\', or to exit enter \'" + "X".green + ": " = gets.chomp.capitalize #Case to Route user case when "R" #Takes user back to original plants puts "Now returning you to the plants list for zip-code #{zip}." (zip) when "N" #Clears PlantScraper::Plant class array @@all and takes user back to new search PlantScraper::Plant.clear start when "X" #Ends program exit end ## ask for next 20 results end else puts "You entered an incorrect zip code please enter a new zip code" start end end |
#plant_type_filter ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/plant_info_scraper/cli.rb', line 154 def plant_type_filter print "For Plant Type, Enter \'" + "A".green + "\' for Any, \'" + "N".green + "\' for Annuals and \'" + "P".green + "\' for Perenials, only choose one Plant Type: " plant_type_entry = gets.chomp.upcase #checking that the sun filter is on a single digit and is only of 4 values filterable if plant_type_entry.length > 1 || !(["A", "N", "P"].include?(plant_type_entry)) puts "Your Entry was Incorrect Please Re-Enter Plant Type" plant_type_entry else #Converting the plant-type filter to a URL appropriate value case plant_type_entry when "A" plant_type_entry = "" when "N" plant_type_entry = "Annual" when "P" plant_type_entry = "Perennial" end end plant_type_entry end |
#start ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/plant_info_scraper/cli.rb', line 3 def start print "\n\n" puts "Welcome to the Unofficial but Amazing Plant Scraper CLI!!!" print "This Gem allows the user to search for plants which thrive in your region. Please enter your zip-code to continue: " zip = zip_code? print "\n\n" print "If you would like to filter results by sunlight, height, or plant type enter \'" + "Y".green + "\' or " + "any key to continue.".green + ": " if gets.chomp.capitalize == "Y" print "\n\n" sun_entry = sun_filter height_entry = height_filter plant_type_entry = plant_type_filter PlantScraper::Scraper.scrape_zip_with_attributes(zip, sun_entry, height_entry, plant_type_entry) elsif PlantScraper::Scraper.scrape_by_zip(zip) else start end print "\n\n" (zip) print "\n\n" end |
#sun_filter ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/plant_info_scraper/cli.rb', line 100 def sun_filter print "For Sunlight, Enter \'" + "A".green + "\' for Any, \'" + "F".green + "\' for Full, \'" + "P".green + "\' for Partial, or \'" + "S".green + "\' for Shade. Only Choose One: " sun_entry = gets.chomp.upcase #checking that the sun filter is on a single digit and is only of 4 values filterable if sun_entry.length > 1 || !(["A", "P", "F", "S"].include?(sun_entry)) puts "Your Entry was Incorrect Please Re-Enter Sun Type" sun_filter else #Converting the sun filter to a URL appropriate value case sun_entry when "A" sun_entry = "" when "F" sun_entry = "Sun" when "P" sun_entry = "Part+Sun" when "S" sun_entry = "Shade" end end sun_entry end |
#zip_code? ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/plant_info_scraper/cli.rb', line 27 def zip_code? zip = gets.chomp if zip.length < 5 || zip.length > 5 || !/\A\d+\z/.match(zip) print "Your Zip Code entry was incorrect. Please re-enter: " zip_code? else puts zip.to_i zip end end |