Class: Adventures::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/adventures/cli.rb

Constant Summary collapse

@@ACTIVITIES =
[["Backpacking", "Bodysurfing", "Camping", "Canoeing"], ["Cycling", "Diving", "Fishing", "Fitness"], ["Hiking", "Kayaking", "Kiteboarding", "Mountain Biking"], ["Photography", "Rafting", "Rock Climbing", "Running"], ["Skiing", "Snowboarding", "Snowshoeing", "Stand Up Paddle"], ["Surfing", "Swimming", "Yoga"]]

Instance Method Summary collapse

Instance Method Details

#callObject



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/adventures/cli.rb', line 5

def call
	puts "Welcome, let's find your next adventure!"
	puts "Type 'exit' to quit at any time."
	puts "Which state would you like to see adventures for? Enter the full name."
	state = gets.strip.downcase.gsub(' ', '-')
	puts "\n"
	if state == "exit"
		exit
	end
	start(state)
end

#continueObject



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
# File 'lib/adventures/cli.rb', line 42

def continue
	puts "Which adventure would you like to learn more about? Enter the number."
	choice = gets.strip.to_i
	puts "\n"
	count = Adventures::Adventure.all.size
	case choice 
	when 1..count
		puts "Here are the details:"
		puts "\n"
		adventure = Adventures::Adventure.find(choice)
		list_details(adventure)
		puts "\n"
		puts "Would you like to see another adventure? Enter Y or N"
		input = gets.strip.downcase
		if input == "y"
			puts "\n"
			list_adventures
			puts "\n"
			continue
		else
			puts "\n"
			puts "Thanks, and have a good adventure!"
			exit
		end
	else
		puts "Please enter a valid number."
		continue
	end
end

#list_activitiesObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/adventures/cli.rb', line 73

def list_activities
	activities = @@ACTIVITIES[0].collect.with_index {|activity, index|
		 "#{index +1}. #{activity} " }
		puts activities.join

	activities = @@ACTIVITIES[1].collect.with_index(4) {|activity, index|
		 "#{index +1}. #{activity} " }
		puts activities.join

	activities = @@ACTIVITIES[2].collect.with_index(8) {|activity, index|
		 "#{index +1}. #{activity} " }
		puts activities.join

	activities = @@ACTIVITIES[3].collect.with_index(12) {|activity, index|
		 "#{index +1}. #{activity} " }
		puts activities.join

	activities = @@ACTIVITIES[4].collect.with_index(16) {|activity, index|
		 "#{index +1}. #{activity} " }

	activities = @@ACTIVITIES[5].collect.with_index(20) {|activity, index|
		 "#{index +1}. #{activity} " }
		puts activities.join
end

#list_adventuresObject



98
99
100
101
102
# File 'lib/adventures/cli.rb', line 98

def list_adventures
	 Adventures::Adventure.all.each_with_index do |a, index|
	 	puts "#{index + 1}. #{a.title} (#{a.location})"
	 end
end

#list_details(adventure) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/adventures/cli.rb', line 104

def list_details(adventure)
	puts <<~DOC
		Activities: #{adventure.suggested_activities}
		Skill Level: #{adventure.skill_level}
		Season: #{adventure.season}
		Trail Type: #{adventure.trail_type}
		RT Distance:#{adventure.rt_distance}
		Elevation Gain: #{adventure.elevation_gain}
		\n #{adventure.summary}
		\n #{adventure.description}
	DOC
end

#start(state) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/adventures/cli.rb', line 17

def start(state)
		puts "What kind of activity are you in the mood for? Enter the number."
		puts "\n"
		list_activities
		puts "\n"
		input = gets.strip.to_i
		puts "\n"
		if input == "exit"
			exit
		elsif input.between?(1, 23)
			activity = @@ACTIVITIES.flatten[input - 1].downcase
			Adventures::Scraper.new.gather_adventures(activity, state)
			if Adventures::Adventure.all.empty?
				puts "There are no adventures for that activity. Please try another activity."
				start(state)
			end
			puts "The following adventures are recommended for #{activity}:"
			puts "\n"
			list_adventures
			puts "\n"
			continue
		end

end