Class: Landmarks::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



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

def call
  puts ""
  puts "WELCOME TO TOP 20 ST. PETERSBURG ARCHITECTURAL LANDMARKS!"
  @scraper = Landmarks::Scraper.new
  @scraper.print_the_title
  @scraper.scrape_landmarks_index
  puts ""
  print_landmarks_index
  puts ""
  start
end


76
77
78
79
80
81
82
83
84
85
# File 'lib/landmarks/cli.rb', line 76

def print_landmarks_index
  Landmarks::Landmark.all.each.with_index do |el, index|
    if el.name.include?("\r\n")
      puts "#{index+1}.#{el.name}".gsub("\r\n", "")
    else
      puts "#{index+1}.\t#{el.name}"
    end
  end
  nil
end

#startObject



17
18
19
20
21
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/landmarks/cli.rb', line 17

def start
  puts "Please enter the number of the landmark you would like more information on:"
  input = gets.chomp.to_i
  if input.between?(1, 20)

    landmark = Landmarks::Landmark.find(input)
    # @scraper.scrape_additional_details(landmark)
    puts "\t\n"
    puts landmark.name.strip.upcase
    puts "\t\n"
    puts "\t\t\t\t\t\t================== Description of the Landmark =================="
    puts "\t\n"
    puts landmark.description
    puts "\t\n"
    puts "\t\t\t\t\t\t================================================================="
    puts "\t\n"
    puts "Would you like to check the availability of directions, contact information and business hours? y/n"
    answer = gets.chomp.downcase

    if answer == "y"
      puts "\t\n"
      puts "\t\t\t\t\t\t====== Directions, contact information and business hours ======"
      puts "\t\n"
      puts landmark.directions
      puts "\t\n"
      puts "\t\t\t\t\t\t================================================================="
      puts "\t\n"
      puts "Would you like to find out more about another landmark? y/n"
      response = gets.chomp.downcase

      if response == "y"
        start
      else
        puts "\t\n"
        puts "Thank you for your interest! Have a great day, and welcome again in the future!"
        puts "\t\n"
        puts "\t\t\t**************************"
        puts "\t\n"
      end

    else
      puts "\t\n"
      puts "Would you like to find out more about another landmark? y/n"
      response = gets.chomp.downcase
      if response == "y"
        start
      else
        puts "Thank you for your interest! Have a great day, and welcome again in the future!"
        puts "\t\n"
        puts "\t\t\t**************************"
        puts "\t\n"
      end
    end
  else
    puts "Please enter a number from 1 to 20!"
    start
  end
end