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

[View source]

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

[View source]

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

def call
  welcome
end

#listObject

[View source]

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/UrgentCare/CLI.rb', line 40

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

[View source]

88
89
90
91
92
93
94
# File 'lib/UrgentCare/CLI.rb', line 88

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

#office_detailsObject

[View source]

56
57
58
59
60
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
# File 'lib/UrgentCare/CLI.rb', line 56

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 "Office 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

[View source]

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

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

[View source]

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