Class: UtahCountyAaMeetingFinder::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



3
4
5
6
7
# File 'lib/utah_county_aa_meeting_finder/cli.rb', line 3

def call
  puts "Welcome to Utah County AA Meeting Finder"
  UtahCountyAaMeetingFinder::Scraper.new.make_meetings("http://www.simeetings.com/LA/UT/OremMtgs.html")
list_meetings
end

#display_meetings(day) ⇒ Object



26
27
28
29
30
# File 'lib/utah_county_aa_meeting_finder/cli.rb', line 26

def display_meetings(day)
 UtahCountyAaMeetingFinder::Meetings.find_by_day(day).each_with_index do |meeting, index|
  puts "#{index+1}. #{meeting.time} #{meeting.name}"
 end
end

#goodbyeObject



59
60
61
# File 'lib/utah_county_aa_meeting_finder/cli.rb', line 59

def goodbye
  puts "Thanks for checking in!"
end

#list_meetingsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/utah_county_aa_meeting_finder/cli.rb', line 10

def list_meetings
  puts "Please pick a day you would like to view meetings for"
  input = gets.strip

  if input.downcase == "exit"
    goodbye

  elsif  ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"].include? input.downcase
   display_meetings(input)
    meeting_address(input)
  else
    puts "I'm sorry, I don't understand"
    list_meetings
  end
end

#meeting_address(day) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/utah_county_aa_meeting_finder/cli.rb', line 32

def meeting_address(day)
puts "Please select the number of the meeting you would like directions for."


meetings = UtahCountyAaMeetingFinder::Meetings.find_by_day(day)
  input = gets.strip
    if input.downcase == "exit"
    goodbye
  elsif input.to_i > meetings.size
    puts "There are only #{meetings.size} meetings for this day"
    meeting_address(day)
    else
      corrected_input = input.to_i - 1
      selected_meeting = meetings[corrected_input]
      puts  "#{selected_meeting.address}"

      puts "Would you like to see more meetings? Type yes or no."
      input = gets.strip
      if input.downcase == "yes"
        list_meetings
      elsif input.downcase == "no"
        goodbye
    end
  end
end