Class: BrewerySearch::CLI
- Inherits:
-
Object
- Object
- BrewerySearch::CLI
- Defined in:
- lib/brewery_search/cli.rb
Constant Summary collapse
- VALID_STATES =
["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"]
Instance Method Summary collapse
-
#breweries_by_city ⇒ Object
will return a list of breweries in the specified city.
-
#ind_brewery_info(brewery) ⇒ Object
returns an info sheet for a given brewery.
-
#list_breweries(state_input) ⇒ Object
it will return a list of breweries from the state specified by the user, in alphabetical order by Brewery name.
-
#menu ⇒ Object
creates flow for allowing user to select a specific brewery and obtain additional info or take other actions.
-
#quit ⇒ Object
it will terminate the program if the user so chooses.
- #start ⇒ Object
-
#welcome_screen ⇒ Object
launches the CLI and greets the user with a welcome screen, prompts user to enter a state to search.
Instance Method Details
#breweries_by_city ⇒ Object
will return a list of breweries in the specified city
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/brewery_search/cli.rb', line 79 def breweries_by_city city_input = nil puts "Please enter the name of the city you would like to filter by:" city_input = gets.strip.downcase.split.map{|word| word.capitalize}.join(' ') @last_search = BrewerySearch::Brewery.find_by_city(city_input) puts "Displaying results:" @last_search.each.with_index {|brewery, index| puts "#{index + 1}. #{brewery.name} -- #{brewery.city}, #{brewery.state} -- #{brewery.type != "" ? brewery.type : "N/A" }"} self. end |
#ind_brewery_info(brewery) ⇒ Object
returns an info sheet for a given brewery
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/brewery_search/cli.rb', line 139 def ind_brewery_info(brewery) puts "\n*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*" puts "Brewery Name: #{brewery.name}" puts "Brewery Address: #{brewery.address != nil ? brewery.address : "N/A"}" puts "Brewery Location: #{brewery.city}, #{brewery.state}" puts "Brewery Phone #: #{brewery.phone != nil ? brewery.phone : "N/A"}" puts "Brewery Type: #{brewery.type != "" ? brewery.type : "N/A" }" puts "Brewery Website: #{brewery.website != nil ? brewery.website : "N/A" }" puts "Brewery Facebook: #{brewery.facebook != nil ? brewery.facebook : "N/A" }" puts "Brewery Twitter: #{brewery.twitter != nil ? brewery.twitter : "N/A" }" puts "Brewery Instagram: #{brewery.instagram != nil ? brewery.instagram : "N/A" }" puts "Brewery Youtube: #{brewery.youtube != nil ? brewery.youtube : "N/A" }" puts "" puts "Brewery Overview: #{brewery.overview.strip}" puts "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*" puts "\nYou can say 'Website', 'Facebook', 'Twitter', 'Instagram', or" puts "'Youtube' to visit the page. Otherwise say 'menu' if you'd like" puts "to return, or 'exit' if you'd like to quit." end |
#list_breweries(state_input) ⇒ Object
it will return a list of breweries from the state specified by the user, in alphabetical order by Brewery name
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/brewery_search/cli.rb', line 64 def list_breweries(state_input) #checking to ensure we have not already scraped the state being searched if BrewerySearch::Brewery.find_by_state(state_input) != [] @last_search = BrewerySearch::Brewery.find_by_state(state_input) else BrewerySearch::Scraper.scrape_state(state_input) @last_search = BrewerySearch::Brewery.find_by_state(state_input) end puts "Displaying results:" puts "" @last_search.each.with_index {|brewery, index| puts "#{index + 1}. #{brewery.name} -- #{brewery.city}, #{brewery.state} -- #{brewery.type != "" ? brewery.type : "N/A" }"} end |
#menu ⇒ Object
creates flow for allowing user to select a specific brewery and obtain additional info or take other actions
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/brewery_search/cli.rb', line 93 def puts "\nPlease enter the number of a brewery for additional information." puts "To see a specific city, enter 'city', or enter 'relist' to show results from the state again." puts "Otherwise, you can enter 'new search' to search again or 'exit' to quit." input = nil input = gets.strip.downcase if (input.to_i > 0) && (input.to_i <= @last_search.size) #specific to a valid brewery selection brewery = @last_search[input.to_i - 1] #uses @last_search to determine if user is at state or city level and to present the correct brewery and options #checks to ensure the profile for the brewery being checked has not been scraped already brewery.address != nil ? brewery : BrewerySearch::Scraper.scrape_profile(brewery) #create display card for brewery self.ind_brewery_info(brewery) = gets.strip.downcase #control flow specific to #ind_brewery_info result if brewery.instance_variables.any? {|attr| "@#{}" == attr.to_s} Launchy.open("#{brewery.send()}") {|exception| puts "Attempted to open #{brewery.send()} but failed due to : #{exception}"} self. elsif == "menu" self. elsif == "exit" self.quit else puts "Invalid entry received. Returning to menu." self. end elsif input == "relist" self.list_breweries(@last_searched_state) self. elsif input == "new search" self.start elsif input == "city" self.breweries_by_city elsif input == "exit" self.quit else puts "Invalid entry received. Please select a number, 'city', 'new search', or 'exit'." self. end end |
#quit ⇒ Object
it will terminate the program if the user so chooses
160 161 162 163 |
# File 'lib/brewery_search/cli.rb', line 160 def quit puts "Thank you for using Brewery Search. Have a great day!" exit end |
#start ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/brewery_search/cli.rb', line 44 def start puts "Please enter the abbreviation for the state you'd like to search:" @last_searched_state = gets.strip.upcase if VALID_STATES.include?(@last_searched_state) self.list_breweries(@last_searched_state) elsif @last_searched_state.downcase == "exit" self.quit elsif @last_searched_state.downcase == "brewbound" Launchy.open("https://www.brewbound.com/") self.start else puts "Invalid entry received." self.start end self. end |
#welcome_screen ⇒ Object
launches the CLI and greets the user with a welcome screen, prompts user to enter a state to search
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/brewery_search/cli.rb', line 10 def welcome_screen puts "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*" puts "AL ..,,,,,,... .. .. . .. MT" puts "AK (# * NE" puts "AZ ,# .','.'.'.'.'.'.'. , NV" puts "AR .,,.,............. ,., NH" puts "CA ,******,,,,,,,,,,,....***@, / NJ" puts "CO ,/((#(#%##%####((///*,(((& NM" puts "CT Welcome *((#(#############(((/((/# ,,. * NY" puts "DE *(((###############(((((// *. NC" puts "FL to *((((#######%#####(((/((/( .,. * ND" puts "GA *((((#############(((/((// ,. ( OH" puts "HI Brewery */((##############((((((/* *. , OK" puts "ID *((((#############(((/((/* *. ( OR" puts "IL Search *(((##############((((((/* *. . PA" puts "IN *(((###############(((((/* *. ( RI" puts "IA /(((###############(((((/* ,. * SC" puts "KA /((########%%%#%###(((((/* ,. / SD" puts "KY /((######%%%%%%%####((#(/* *,.* TN" puts "LA /(#####%%%%%%%%%%###((#(/* *. / TX" puts "ME /(####%%%%%%%%%%%###((#(%/ ,.. . UT" puts "MD .((###%%%%%%%%%%%%%###(#(@ ...... VT" puts "MA .((###%%%%%%%%%%%%%###(#(@ .... . VA" puts "MI ,(###%%%%%%%%%%%%%%###(##/ WA" puts "MN ,.*#//%/###(#(##(#//. ,,/ WV" puts "MS , ./*** ,,,*./ WI" puts "MO , /.. .**...// WY" puts "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*" puts "* All information contained is referenced from BrewBound. *" puts "* Type 'BrewBound' to visit them! *" puts "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*" self.start end |