Class: HikingGuide::CommandLineInteface
- Inherits:
-
Object
- Object
- HikingGuide::CommandLineInteface
- Defined in:
- lib/hiking_guide/command_line_interface.rb
Constant Summary collapse
- BASE_PATH =
"http://www.hikingupward.com/"
Class Method Summary collapse
- .add_trail_attributes ⇒ Object
- .display_all_trails ⇒ Object
- .display_trail_details(trail) ⇒ Object
- .exit ⇒ Object
- .greeting ⇒ Object
- .hit_the_trails ⇒ Object
- .main_menu ⇒ Object
- .make_trails ⇒ Object
- .run ⇒ Object
- .state_list(state_trails_list) ⇒ Object
- .state_menu(state_trails_list) ⇒ Object
Class Method Details
.add_trail_attributes ⇒ Object
15 16 17 18 19 20 |
# File 'lib/hiking_guide/command_line_interface.rb', line 15 def self.add_trail_attributes HikingGuide::Trail.all.each do |trail| attributes = HikingGuide::Scraper.scrape_trail_profile(trail.profile_url) trail.add_trail_attributes(attributes) end end |
.display_all_trails ⇒ Object
154 155 156 157 158 159 |
# File 'lib/hiking_guide/command_line_interface.rb', line 154 def self.display_all_trails HikingGuide::Trail.all.each do |trail| display_trail_details(trail) end end |
.display_trail_details(trail) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/hiking_guide/command_line_interface.rb', line 140 def self.display_trail_details(trail) puts "----------------------".colorize(:light_green).on_green puts " #{trail.name.upcase} ".colorize(:black).on_green puts " state:".colorize(:black).on_green + " #{trail.state}" puts " length:".colorize(:black).on_green + " #{trail.length}" puts " hiking time:".colorize(:black).on_green + " #{trail.hiking_time}" puts " elevation gain:".colorize(:black).on_green + " #{trail.elevation_gain}" puts " link to map pdf:".colorize(:black).on_green + " #{trail.map_pdf_link}" puts " trail description:".colorize(:black).on_green + " #{trail.description}" puts " * * * * * * * ".colorize(:light_green) puts "To read more about this trail, please visit #{trail.profile_url}" puts "----------------------".colorize(:light_green).on_green end |
.exit ⇒ Object
135 136 137 138 |
# File 'lib/hiking_guide/command_line_interface.rb', line 135 def self.exit puts "Thanks for visiting -- Happy Trails!" hit_the_trails end |
.greeting ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hiking_guide/command_line_interface.rb', line 22 def self.greeting puts "Setting up your command line trail guide -" puts "Please wait a minute while we gather the trail details..." sleep(1) puts " /\\ ".light_red.on_red puts " / \\ ".light_red.on_red puts " / \\/\\ ".light_red.on_red puts " / / \\ ".light_red.on_red sleep(1) make_trails puts "getting closer..." puts " /\\ ".light_yellow.on_yellow puts " /\\ / \\ ".light_yellow.on_yellow puts " / \\/ \\ ".light_yellow.on_yellow puts " / \\/\\ \\ ".light_yellow.on_yellow puts " / / \\ \\ ".light_yellow.on_yellow puts " / / \\ \\".light_yellow.on_yellow add_trail_attributes puts "All set!" sleep(1) hit_the_trails puts "" puts "Welcome to Hiking Guide!".black.on_green puts "" puts "The information in Hiking Guide comes from a volunteer organization called Hiking Upward (http://www.hikingupward.com/). If you find the information useful, please consider volunteering as a Trail Contributer, or donating to the organization." puts "" end |
.hit_the_trails ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/hiking_guide/command_line_interface.rb', line 50 def self.hit_the_trails puts " /\\ ".light_green.on_green puts " / \\ ".light_green.on_green puts " / \\ /\\ ".light_green.on_green puts " / \\ / \\ ".light_green.on_green puts " / /\\ / \\ /\\ ".light_green.on_green puts " / / \\ / / \\ ".light_green.on_green puts " / / \\/ /\\/ \\ ".light_green.on_green puts " / / \\ / \\ \\ ".light_green.on_green puts "_______________________________".black.on_green puts "===============================".black.on_green puts " H I T T H E T R A I L S ! ".light_green.on_green puts "===============================".black.on_green end |
.main_menu ⇒ Object
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 98 |
# File 'lib/hiking_guide/command_line_interface.rb', line 65 def self. puts "Where would you like to explore?".black.on_green puts "(1) Maryland hikes" puts "(2) Pennsylvania hikes" puts "(3) North Carolina hikes" puts "(4) Virginia hikes" puts "(5) West Virginia hikes" puts "please enter 1-5:" input = gets.strip if input == "1" puts "Here is a list of trails in Maryland:".black.on_green (HikingGuide::Trail.md) elsif input == "2" puts "Here is a list of trails in Pennsylvania:".black.on_green (HikingGuide::Trail.pa) elsif input == "3" puts "Here is a list of trails in North Carolina:".black.on_green (HikingGuide::Trail.nc) elsif input == "4" puts "Here is a list of trails in Virgini:".black.on_green (HikingGuide::Trail.va) elsif input == "5" puts "Here is a list of trails in West Virginia:".black.on_green (HikingGuide::Trail.wv) elsif input.upcase == "ALL TRAILS" display_all_trails elsif input.upcase == "EXIT" exit else puts "I'm not sure what you mean -- let's see if we can find the trail again!".black.on_green puts "<< at any time you can exit by typing 'exit' >>".black.on_green end end |
.make_trails ⇒ Object
9 10 11 12 13 |
# File 'lib/hiking_guide/command_line_interface.rb', line 9 def self.make_trails HikingGuide::Trail.reset_all trails_array = HikingGuide::Scraper.scrape_trail_list(BASE_PATH) HikingGuide::Trail.create_from_collection(trails_array) end |
.run ⇒ Object
4 5 6 7 |
# File 'lib/hiking_guide/command_line_interface.rb', line 4 def self.run greeting end |
.state_list(state_trails_list) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/hiking_guide/command_line_interface.rb', line 100 def self.state_list(state_trails_list) counter = 1 state_trails_list.each do |trail| puts "(#{counter}) #{trail.name}" counter += 1 end end |
.state_menu(state_trails_list) ⇒ Object
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 |
# File 'lib/hiking_guide/command_line_interface.rb', line 108 def self.(state_trails_list) state_list(state_trails_list) puts "Please type the number of any trail you'd like to learn more about" puts "Or if you wish to return to the main menu, type 'menu'" input = gets.strip if input.to_i > 0 && input.to_i <= state_trails_list.size display_trail_details(state_trails_list[input.to_i-1]) puts "Would you like to read about another of these trails? (y/n)" response = gets.strip if response.upcase == "Y" (state_trails_list) elsif response.upcase == "EXIT" exit else end elsif input.upcase == "MENU" elsif input.upcase == "EXIT" exit else puts "I'm not sure what you mean -- let's see if we can find the trail again!".black.on_green puts "<< at any time you can exit by typing 'exit' >>".black.on_green (state_trails_list) end end |