Class: Urgentcare::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/UrgentCare/CLI.rb

Instance Method Summary collapse

Constructor Details

#initialize(scraper: Urgentcare::Scraper.new, offices: Urgentcare::Office.all) ⇒ CLI

remove strict dependency on other classes



8
9
10
11
# File 'lib/UrgentCare/CLI.rb', line 8

def initialize(scraper: Urgentcare::Scraper.new, offices: Urgentcare::Office.all)
  @scraper = scraper
  @offices = offices
end

Instance Method Details

#callObject



13
14
15
# File 'lib/UrgentCare/CLI.rb', line 13

def call
  welcome
end

#listObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/UrgentCare/CLI.rb', line 48

def list
  puts " "
  location = $stdin.gets.chomp 
  if location == "Exit" ||location == "exit"
    puts "Thank you and Goodbye!"
  elsif location != "Exit" || location != "exit"
    location = location.to_i 
    $index = location - 1
    loading_message
    @scraper.get_clinic_site
    office_details
  else 
    puts "Invalid response"
  end
end

#loading_messageObject



29
30
31
32
33
34
35
# File 'lib/UrgentCare/CLI.rb', line 29

def loading_message
  puts " "
  puts "Retrieving data...."
  puts "Loading......"
  puts "............."
  puts " "
end

#office_detailsObject



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
# File 'lib/UrgentCare/CLI.rb', line 64

def office_details
  if $index != "Exit" || $index != "exit"
    puts " "
    puts " "
    puts " "
    puts "---"
    puts "Office Name: #{@offices[$index].name}"
    puts "Office Number: #{@offices[$index].phone_number}"
    puts "Appointment URL: #{@offices[$index].url}"
    puts "Office Next Available Appointment: #{@offices[$index].next_available}"
    puts "---"
    puts " "
    puts " "
    puts " "

  else
    puts "No results found. Please try again."
  end
    puts " "
    puts " "
    puts " "
    puts "Would you like to select another office from the list?"
    puts " "
  @offices.each_with_index do |office, i|
    puts "#{i + 1}. #{office.name}"
  end
    puts " "
    puts "If not, please type exit."
    puts " "
  list
end

#office_listObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/UrgentCare/CLI.rb', line 37

def office_list
  @scraper.get_office_list
  puts "Please choose a number from the following list for details on
  an Urgent Care location."
  puts " "
  @offices.each_with_index do |office, i|
    puts "#{i + 1}. #{office.name}"
  end
   list
end

#welcomeObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/UrgentCare/CLI.rb', line 17

def welcome
  #puts displays with a new line 
  puts " "
  puts " "
  puts "Welcome to the Urgent Care CLI"
  puts " "
  puts " "
  puts " "
  loading_message 
  office_list 
end