Class: ClosestWeightliftingGem::CLI
- Inherits:
-
Object
- Object
- ClosestWeightliftingGem::CLI
- Defined in:
- lib/closest_weightlifting_gem/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #good_bye ⇒ Object
- #line ⇒ Object
- #load_gyms ⇒ Object
-
#main_menu ⇒ Object
address = gets.chomp end.
- #open_in_browser(gym) ⇒ Object
- #options(menu, data = nil) ⇒ Object
- #process_gym(gym) ⇒ Object
- #process_gyms(gyms) ⇒ Object
- #process_main ⇒ Object
- #show_gym(gym) ⇒ Object
- #show_gyms(gyms) ⇒ Object
Instance Method Details
#call ⇒ Object
2 3 4 5 6 |
# File 'lib/closest_weightlifting_gem/cli.rb', line 2 def call load_gyms end |
#good_bye ⇒ Object
200 201 202 |
# File 'lib/closest_weightlifting_gem/cli.rb', line 200 def good_bye puts "Adios friend. Hope you come back to lift weights again!" end |
#line ⇒ Object
196 197 198 |
# File 'lib/closest_weightlifting_gem/cli.rb', line 196 def line "="*80 end |
#load_gyms ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/closest_weightlifting_gem/cli.rb', line 8 def load_gyms puts <<-DOC.gsub /^\s*/, '' Welcome to the Closest Weightlifting Gem! Give me a few minutes to fetch a fresh data widget doohicky from the cloud nebula... DOC ClosestWeightliftingGem::Scraper.scrape_main end |
#main_menu ⇒ Object
address = gets.chomp end
28 29 30 31 32 |
# File 'lib/closest_weightlifting_gem/cli.rb', line 28 def puts "What do you want to do now?" (__method__) end |
#open_in_browser(gym) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/closest_weightlifting_gem/cli.rb', line 99 def open_in_browser(gym) if gym.website == "none" puts "Sorry, that gym doesn't have a website. :(" elsif !gym.website.include?("http") system("open", "http://#{gym.website}") else system("open", "#{gym.website}") end end |
#options(menu, data = nil) ⇒ Object
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 95 96 97 |
# File 'lib/closest_weightlifting_gem/cli.rb', line 61 def (, data=nil) = .to_s case when "main_menu" puts line puts <<-DOC.gsub(/^\s*/,'') 1. List By State Abbreviation (ex. AL, AK, CA, FL, IL, NY, etc.) 2. Search Club Names 3. Exit DOC process_main when "show_gyms" puts line puts <<-DOC.gsub(/^\s*/,'') 1. Select Gym By Number 2. Replay List 3. Main menu 4. Exit DOC process_gyms(data) when "show_gym" puts line puts <<-DOC.gsub(/^\s*/,'') 1. Open Website 2. Back to State Results 3. Main menu 4. Exit DOC process_gym(data) else puts "WTF" end end |
#process_gym(gym) ⇒ Object
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 |
# File 'lib/closest_weightlifting_gem/cli.rb', line 167 def process_gym(gym) input = nil until input == "exit" input = gets.strip.downcase case input when "1" open_in_browser(gym) ("show_gym", gym) when "2" show_gyms(ClosestWeightliftingGem::Gym.find_by_state(gym.state)) when "3" when "4" good_bye exit when "exit" good_bye exit else puts "I didn't understand that, please try again." end end end |
#process_gyms(gyms) ⇒ Object
138 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 |
# File 'lib/closest_weightlifting_gem/cli.rb', line 138 def process_gyms(gyms) input = nil until input == "exit" input = gets.strip.downcase case input when "1" puts "Select a gym by the number:" gym_num = gets.chomp.to_i - 1 show_gym(gyms[gym_num]) when "2" show_gyms(gyms) when "3" when "4" good_bye exit when "exit" good_bye exit else puts "I didn't understand that, please try again." end end end |
#process_main ⇒ Object
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/closest_weightlifting_gem/cli.rb', line 109 def process_main input = nil while input != "exit" input = gets.strip.downcase case input when "1" puts "Which state?" state = gets.chomp.upcase show_gyms(ClosestWeightliftingGem::Gym.find_by_state(state)) when "2" puts "What do you want to search for?" search_term = gets.chomp.upcase show_gyms(ClosestWeightliftingGem::Gym.find_by_name(search_term)) when "3" good_bye exit when "exit" good_bye exit else puts "I didn't understand that, please try again." end end end |
#show_gym(gym) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/closest_weightlifting_gem/cli.rb', line 49 def show_gym(gym) ClosestWeightliftingGem::Scraper.scrape_attributes(gym) if !gym.coach puts "Name: #{gym.name}" puts "Address: #{gym.full_address}" puts "Director: #{gym.director}" puts "Coach: #{gym.coach}" puts "Website: #{gym.website}" (__method__, gym) end |
#show_gyms(gyms) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/closest_weightlifting_gem/cli.rb', line 34 def show_gyms(gyms) width = 80 puts line puts "OK, your search yielded #{gyms.size} gyms!\n" puts "Here's the list: " puts line puts " Gym Name".ljust(width/2)+" City" gyms.each_with_index do |gym, i| puts "#{(i+1).to_s.rjust(3)}. #{gym.name.ljust(width/2)} #{gym.city}, #{gym.state}" end (__method__, gyms) end |