Class: ThisDayInHistory::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



3
4
5
# File 'lib/this_day_in_history/cli.rb', line 3

def call
   welcome  
end

#exitObject



60
61
62
# File 'lib/this_day_in_history/cli.rb', line 60

def exit
  puts "Goodbye. Come back tomorrow for more great events in history!"
end

#find_by_number(input) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/this_day_in_history/cli.rb', line 32

def find_by_number(input)
event = ThisDayInHistory::Events.all[input-1]
puts "Title: #{event.title}"
puts "Year: #{event.year}" 
puts "Category: #{event.category}" 
  
if event.category == "Lead Story"
  puts "#{event.story}"
else 
  puts "#{event.full_story}"
  end
end

#listObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/this_day_in_history/cli.rb', line 18

def list
  ThisDayInHistory::Events.list_by_title
  puts "***************************************"
  puts "Which event would you like to learn more about?(select a number)"
  input = gets.strip.to_i
  if input <= ThisDayInHistory::Events.all.length && input > 0
    find_by_number(input)
    more_options
  else
    puts "Please choose a number on the list"
    list
  end
end

#make_eventsObject



14
15
16
# File 'lib/this_day_in_history/cli.rb', line 14

def make_events
  ThisDayInHistory::History_Scraper.new.make_events
end

#more_optionsObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/this_day_in_history/cli.rb', line 47

def more_options
  input = ""
  puts "***************************************"
  puts "Finished reading for today? Type 'exit'"
  puts "To see the list again press 'enter'"
  input = gets.strip.downcase
  if input == "exit"
    exit
  else
    list
  end
end

#welcomeObject



7
8
9
10
11
12
# File 'lib/this_day_in_history/cli.rb', line 7

def welcome
  ThisDayInHistory::Events.reset_all
  make_events
  puts "***********Today in History***********"
  list
end