14
15
16
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/podcast_book_club/cli.rb', line 14
def call
until @input == "exit"
puts "\n\nEnter your selection:"
@input = gets.chomp.downcase
case @input
when "1", "this week"
first_date = @today - @today.wday
episodes = Episode.find_by_date(first_date, @today)
select_episodes(episodes)
when "2", "last week"
first_date = @today - @today.wday - 7
last_date = @today - @today.wday
episodes = Episode.find_by_date(first_date, last_date)
select_episodes(episodes)
when "3", "this month"
first_date = @today - @today.mday + 1
episodes = Episode.find_by_date(first_date, @today)
select_episodes(episodes)
when "4", "last month"
last_date = @today - @today.mday
first_date = last_date - last_date.mday + 1
episodes = Episode.find_by_date(first_date, last_date)
select_episodes(episodes)
when "5", "this year"
first_date = @today - @today.yday + 1
episodes = Episode.find_by_date(first_date, @today)
select_episodes(episodes)
when "6", "keyword"
puts "\n\nEnter a keyword or phrase:"
keyword = gets.chomp.downcase
episodes = Episode.find_by_keyword(keyword)
select_episodes(episodes)
when "7", "author"
if Book.count > 0
Author.sort_by_name.each { |author| output_author(author) }
else
no_books
end
when "8", "genre"
if Book.count > 0
Genre.sort_by_name.each { |genre| output_genre(genre) }
else
no_books
end
when "9", "search"
if Book.count > 0
puts "\n\nEnter a keyword or phrase:"
keyword = gets.chomp.downcase
books = Book.find_by_keyword(keyword)
books.each_with_index do |book, i|
episodes = book.episode.map { |ep| ep.title}
output_book(book, i+1)
puts "From the episode(s): #{episodes.join(", ")}\n\n"
end
else
no_books
end
when "animal style"
create_library(Episode.all)
when "help"
when "exit"
break
else
unexpected_input
end
end
end
|