Class: NytJourneys::CommandLineInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/nyt_journeys/command_line_interface.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#inputObject

Returns the value of attribute input.



2
3
4
# File 'lib/nyt_journeys/command_line_interface.rb', line 2

def input
  @input
end

Instance Method Details

#callObject



4
5
6
7
8
# File 'lib/nyt_journeys/command_line_interface.rb', line 4

def call
  NytJourneys::Data_Generator.new.make_journeys
  greeting
  start
end

#greetingObject



10
11
12
13
14
15
16
# File 'lib/nyt_journeys/command_line_interface.rb', line 10

def greeting
  puts ""
  puts "~~*~~*~~*~~ New York Times Journeys ~~*~~*~~*~~"
  puts ""
  puts NytJourneys::Scraper.scrape_quotes.sample
  puts ""
end

#list_journeysObject



18
19
20
21
22
23
24
25
26
# File 'lib/nyt_journeys/command_line_interface.rb', line 18

def list_journeys
  puts ""
  puts "~~*~~*~~*~~ Available New York Times Journeys ~~*~~*~~*~~"
  puts ""
  NytJourneys::Journeys.all.each.with_index(1) do |journey, index|
    puts "#{index}. #{journey.name}"
  end
  puts ""
end

#list_typesObject



64
65
66
67
68
69
70
71
72
# File 'lib/nyt_journeys/command_line_interface.rb', line 64

def list_types
  puts ""
  puts "~~*~~*~~*~~ Journeys Focused On ~~*~~*~~*~~"
  puts ""
  NytJourneys::Journeys.types.each.with_index(1) do |type, index|
    puts "#{index}. #{type}"
  end
  puts ""
end


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/nyt_journeys/command_line_interface.rb', line 102

def navigate_category(category)
  puts ""
  puts "Which journey would you like to learn more about? Enter 1 - #{NytJourneys::Journeys.find_by_type(category).count}."
  puts ""
  puts "Enter 'list' to see all journeys."
  puts "Enter 'types' to see journey categories."
  puts "Enter 'exit' to end the program."
  self.input = gets.downcase.strip
  if self.input == "list"
    navigate_journeys
  elsif self.input == "types"
    navigate_types
  elsif self.input.to_i > 0
    if journey = NytJourneys::Journeys.find_by_type(category)[self.input.to_i - 1]
      print_journey(journey)
    end
  end
end


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/nyt_journeys/command_line_interface.rb', line 28

def navigate_journeys
  list_journeys
  puts ""
  puts "Which journey would you like to learn more about? Enter 1 - #{NytJourneys::Journeys.all.count}."
  puts ""
  puts "Enter 'types' to see journey categories."
  puts "Enter 'exit' to end the program."
  self.input = gets.downcase.strip
  if self.input == "types"
    navigate_types
  elsif self.input.to_i > 0
    if journey = NytJourneys::Journeys.find(self.input.to_i)
      print_journey(journey)
    end
  end
end


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/nyt_journeys/command_line_interface.rb', line 74

def navigate_types
  list_types
  puts ""
  puts "Which type of journey would you like to take? Enter 1 - #{NytJourneys::Journeys.types.count}."
  puts ""
  puts "Enter 'list' to see all journeys."
  puts "Enter 'exit' to end the program."
  self.input = gets.downcase.strip
  if self.input == "list"
    navigate_journeys
  elsif self.input.to_i > 0
    if category = NytJourneys::Journeys.types[self.input.to_i - 1]
      print_category(category)
      navigate_category(category)
    end
  end
end


92
93
94
95
96
97
98
99
100
# File 'lib/nyt_journeys/command_line_interface.rb', line 92

def print_category(category)
  puts ""
  puts "~~*~~*~~*~~ Journeys Focused On #{category} ~~*~~*~~*~~"
  puts ""
  NytJourneys::Journeys.find_by_type(category).each.with_index(1) do |journey, index|
    puts "#{index}. #{journey.name}"
  end
  puts ""
end


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/nyt_journeys/command_line_interface.rb', line 45

def print_journey(journey)
  puts ""
  puts "~~*~~*~~*~~ #{journey.name} ~~*~~*~~*~~"
  puts "A Journey Focused On #{journey.type}"
  puts ""
  puts journey.description
  puts ""
  puts "From: #{journey.cost}"
  puts ""
  puts "Journey Duration: #{journey.length}"
  puts ""
  puts "Available Dates:"
  puts journey.dates
  puts ""
  puts "Itinerary:"
  puts journey.itinerary
  puts ""
end

#startObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/nyt_journeys/command_line_interface.rb', line 121

def start
  self.input = nil
  while self.input != "exit"
    puts ""
    puts "Enter 'list' to see all journeys."
    puts "Enter 'types' to see journey categories."
    puts "Enter 'exit' to end the program."
    puts ""
    self.input = gets.downcase.strip
    if self.input == "list"
      navigate_journeys
    elsif self.input == "types"
      navigate_types
    end
  end
  puts ""
  puts NytJourneys::Scraper.scrape_quotes.sample
  puts ""
  puts "Enjoy the journey!"
end