Class: TripAdvisorBest::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



4
5
6
7
8
9
10
11
# File 'lib/tripadvisor_best/cli.rb', line 4

def initialize
  @sites = [
    {class_name: TripAdvisorBest::Museum, url: "https://www.tripadvisor.com/TravelersChoice-Museums#1"},
    {class_name: TripAdvisorBest::Attraction, url: "https://www.tripadvisor.com/TravelersChoice-Attractions"},
    {class_name: TripAdvisorBest::Landmark, url: "https://www.tripadvisor.com/TravelersChoice-Landmarks"}
  ]
  make_highlights
end

Instance Attribute Details

#sitesObject (readonly)

Returns the value of attribute sites.



2
3
4
# File 'lib/tripadvisor_best/cli.rb', line 2

def sites
  @sites
end

Instance Method Details

#add_highlight_details(highlight) ⇒ Object



112
113
114
115
# File 'lib/tripadvisor_best/cli.rb', line 112

def add_highlight_details(highlight)
  attributes = TripAdvisorBest::Scraper.new.scrap_details_page(highlight.url)
  highlight.add_highlight_attributes(attributes)
end

#callObject



22
23
24
25
# File 'lib/tripadvisor_best/cli.rb', line 22

def call
  welcome
  menu
end

#goodbyeObject



117
118
119
# File 'lib/tripadvisor_best/cli.rb', line 117

def goodbye
  puts "Bon voyage!"
end

#highlight_details(class_name, highlight) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/tripadvisor_best/cli.rb', line 99

def highlight_details(class_name, highlight)
  puts"#{highlight.ranking}. - #{highlight.name} - #{highlight.location}".colorize(:yellow)
  puts "  #{highlight.description}".colorize(:light_blue)
  puts "----------------------".colorize(:green)

  puts "Would you like to see another? (y or n)"
  input = gets.strip.downcase

  if input == "y"
    list_highlight_details(class_name)
  end
end

#list_highlight_details(class_name) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/tripadvisor_best/cli.rb', line 83

def list_highlight_details(class_name)
  puts "Which would you like to see in greater detail?"
  input = gets.strip.to_i

  if input.between?(1, 25)
    highlight = class_name.find(input - 1)

    add_highlight_details(highlight)

    highlight_details(class_name, highlight)
  else
    puts "I didn't get that..."
    list_highlight_details(class_name)
  end
end

#list_hightlights(class_name) ⇒ Object



77
78
79
80
81
# File 'lib/tripadvisor_best/cli.rb', line 77

def list_hightlights(class_name)
  class_name.all.each do |highlight|
    puts "#{highlight.ranking}. - #{highlight.name}".colorize(:yellow)
  end
end

#list_optionsObject



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/tripadvisor_best/cli.rb', line 65

def list_options
  puts "Currently you can see..."
  puts ""
  puts <<-DOC
    1. Top 25 Museums
    2. Top 25 Attractions
    3. Top 25 Landmarks
  DOC
  puts ""
  puts "Which would you like to see?"
end

#make_highlightsObject



13
14
15
16
17
18
19
20
# File 'lib/tripadvisor_best/cli.rb', line 13

def make_highlights
  puts "Planning your next big trip..."
  self.sites.each do |site|
    highlights_array = []
    highlights_array = TripAdvisorBest::Scraper.new.scrape_listings_page(site[:url])
    site[:class_name].create_from_collection(highlights_array)
  end
end


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

def menu
  input = nil
  while input != "exit"
    list_options
    input = gets.strip.downcase
    case input
    when "1"
      puts "Here are the top 25 Museums in the world...".colorize(:red)
      list_hightlights(sites[0][:class_name])
      list_highlight_details(sites[0][:class_name])
    when "2"
      puts "Here are the top 25 Attractions in the world...".colorize(:red)
      list_hightlights(sites[1][:class_name])
      list_highlight_details(sites[1][:class_name])
    when "3"
      puts "Here are the top 25 Landmarks in the world...".colorize(:red)
      list_hightlights(sites[2][:class_name])
      list_highlight_details(sites[2][:class_name])
    when "list"
      list_options
    when "exit"
      goodbye
    else
      puts "I'm not sure what you want. Either type 'list' or 'exit'."
      puts ""
    end
  end
end

#welcomeObject



27
28
29
30
31
32
33
34
# File 'lib/tripadvisor_best/cli.rb', line 27

def welcome
  puts ""
  puts "The TripAdvisor Traveler's Choice Awards are out.".colorize(:red)
  puts ""
  puts "Are you ready to travel the world?"
  puts "  (Type 'exit' to leave program.)"
  puts ""
end