Class: Nytimesbooks::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childrens_middleObject (readonly)

Returns the value of attribute childrens_middle.



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

def childrens_middle
  @childrens_middle
end

#childrens_pictureObject (readonly)

Returns the value of attribute childrens_picture.



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

def childrens_picture
  @childrens_picture
end

#childrens_seriesObject (readonly)

Returns the value of attribute childrens_series.



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

def childrens_series
  @childrens_series
end

#combined_fictionObject (readonly)

Returns the value of attribute combined_fiction.



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

def combined_fiction
  @combined_fiction
end

#combined_nonfictionObject (readonly)

Returns the value of attribute combined_nonfiction.



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

def combined_nonfiction
  @combined_nonfiction
end

#hardcover_fictionObject (readonly)

Returns the value of attribute hardcover_fiction.



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

def hardcover_fiction
  @hardcover_fiction
end

#hardcover_nonfictionObject (readonly)

Returns the value of attribute hardcover_nonfiction.



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

def hardcover_nonfiction
  @hardcover_nonfiction
end

#paperback_fictionObject (readonly)

Returns the value of attribute paperback_fiction.



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

def paperback_fiction
  @paperback_fiction
end

#paperback_howtoObject (readonly)

Returns the value of attribute paperback_howto.



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

def paperback_howto
  @paperback_howto
end

#paperback_nonfictionObject (readonly)

Returns the value of attribute paperback_nonfiction.



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

def paperback_nonfiction
  @paperback_nonfiction
end

#young_adultObject (readonly)

Returns the value of attribute young_adult.



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

def young_adult
  @young_adult
end

Instance Method Details

#callObject



4
5
6
7
# File 'lib/nytimesbooks/cli.rb', line 4

def call
  puts "Welcome to the New York Times Best Selling Books list!"
  main_categories
end

#childrens_menuObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/nytimesbooks/cli.rb', line 90

def childrens_menu
    puts "There are 4 Childrens categories:"
    puts "1. Childrens Middle Grade Hardcover 2. Children's Picture Books 3. Children's Series 4. Young Adult Hardcover"
    puts "Which are you interested in? Type 1-4 or exit to leave the program."
      input = gets.chomp.downcase
    case input
    when "1"
      @childrens_middle = Nytimesbooks::Scraper.childrens_middle
      @childrens_middle.each_with_index do |book, i|
        puts "#{i+1}. #{book.name} #{book.author}"
      end
      combined(@childrens_middle, 10)
    when "2"
      @childrens_picture = Nytimesbooks::Scraper.childrens_picture
      @childrens_picture.each_with_index do |book, i|
        puts "#{i+1}. #{book.name} #{book.author}"
      end
      combined(@childrens_picture, 10)
    when "3"
      @childrens_series = Nytimesbooks::Scraper.childrens_series
      @childrens_series.each_with_index do |book, i|
        puts "#{i+1}. #{book.name} #{book.author}"
      end
      combined(@childrens_series, 10)
    when "4"
      @young_adult = Nytimesbooks::Scraper.young_adult
      @young_adult.each_with_index do |book, i|
        puts "#{i+1}. #{book.name} #{book.author}"
      end
      combined(@young_adult, 10)
    when "exit"
      goodbye
    else
      puts "I don't understand your input. Please try again."
  end
end

#combined(array, number = 15) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/nytimesbooks/cli.rb', line 127

def combined(array, number = 15)
  puts "Which of these books would you like to see a description of? Enter 1 - #{number}, or exit to leave."
  input = gets.chomp
  until input == "exit"
    if input == "back"
      main_categories
    elsif input.to_i.between?(1, number)
      input = input.to_i
       puts "#{array[input - 1].name} #{array[input -1].author}."
       puts "#{array[input - 1].bookdescription}"
       puts "Please enter another number to see an additional description, back to return to the main menu, or enter exit to close the program."
    else
       puts "I don't understand your input. Please try again."
       combined(array, number)
     end
     input = gets.chomp
  end
end

#fiction_menuObject



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

def fiction_menu
    puts "There are 3 Fiction categories:"
    puts "1. Combined Print & E-Book Fiction 2. Hardcover Fiction 3. Paperback Trade Fiction"
    puts "Which are you interested in? Type 1-3 or exit to leave the program."
      input = gets.chomp.downcase
    case input
    when "1"
      @combined_fiction = Nytimesbooks::Scraper.combined_fiction
      @combined_fiction.each_with_index do |book, i|
        puts "#{i+1}. #{book.name} #{book.author}"
      end
      combined(@combined_fiction)
    when "2"
      @hardcover_fiction = Nytimesbooks::Scraper.hardcover_fiction
      @hardcover_fiction.each_with_index do |book, i|
        puts "#{i+1}. #{book.name} #{book.author}"
      end
      combined(@hardcover_fiction)
    when "3"
      @paperback_fiction = Nytimesbooks::Scraper.paperback_fiction
      @paperback_fiction.each_with_index do |book, i|
        puts "#{i+1}. #{book.name} #{book.author}"
      end
      combined(@paperback_fiction)
    when "exit"
      goodbye
    else
      puts "I don't understand your input. Please try again."
  end
end

#goodbyeObject



146
147
148
149
# File 'lib/nytimesbooks/cli.rb', line 146

def goodbye
  puts "Enjoy your reading!"
  exit
end

#main_categoriesObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/nytimesbooks/cli.rb', line 9

def main_categories
  puts "Are you interested in seeing 1. Fiction, 2. Nonfiction, or 3. Childrens Best Sellers lists?"
  puts "(Type exit to leave program)"
    input = gets.chomp.downcase
    until input == "exit"
      if input == "1"
        fiction_menu
      elsif input == "2"
        nonfiction_menu
      elsif input == "3"
        childrens_menu
      else
        puts "I don't understand your input. Please try again."
      end
      input = gets.chomp.downcase
   end
   goodbye
end

#nonfiction_menuObject



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

def nonfiction_menu
  puts "There are 3 Nonfiction categories:"
  puts "1. Combined Print & E-Book Nonfiction 2. Hardcover Nonfiction 3. Paperback Nonfiction"
  puts "Which are you interested in? Type 1-3 or exit to leave the program."
    input = gets.chomp.downcase
  case input
  when "1"
    @combined_nonfiction = Nytimesbooks::Scraper.combined_nonfiction
    @combined_nonfiction.each_with_index do |book, i|
      puts "#{i+1}. #{book.name} #{book.author}"
    end
    combined(@combined_nonfiction)
  when "2"
    @hardcover_nonfiction = Nytimesbooks::Scraper.hardcover_nonfiction
    @hardcover_nonfiction.each_with_index do |book, i|
      puts "#{i+1}. #{book.name} #{book.author}"
    end
    combined(@hardcover_nonfiction)
  when "3"
    @paperback_nonfiction = Nytimesbooks::Scraper.paperback_nonfiction
    @paperback_nonfiction.each_with_index do |book, i|
      puts "#{i+1}. #{book.name} #{book.author}"
    end
    combined(@paperback_nonfiction)
  when "exit"
    goodbye
  else
    puts "I don't understand your input. Please try again."
end
end