Class: Bestsellers::CLI

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

Instance Method Summary collapse

Instance Method Details

#byebyeObject



58
59
60
61
# File 'lib/bestsellers/cli.rb', line 58

def byebye
    puts " "
    puts "Thank you for visiting Bestsellers! Enjoy reading your new book!"
end

#callObject



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

def call
    Bestsellers::Scraper.create_bestsellers
    welcome
    list_books
    puts " "
    menu_selection
    byebye
end

#list_booksObject



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

def list_books
    @bestseller_books = Bestsellers::Books.all
    @bestseller_books.each.with_index(1) do |book, index|
        puts "#{index}. #{book.title}"
    end
end


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/bestsellers/cli.rb', line 34

def menu_selection
    input = ""
    while input != "exit"
        puts "Enter the number of the book you want more information on, type 'list' to view the bestsellers list, or type 'exit' to exit."
        puts " "
        input = gets.strip.downcase

        if input == "list"
            list_books
            puts " "
            elsif input.to_i > 20
                puts "Please enter a valid number from the bestsellers list."
            elsif input.to_i > 0
                user_selection = @bestseller_books[input.to_i - 1]
                puts "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
                puts "Title: #{user_selection.title}"
                puts "Author: #{user_selection.author}"
                puts "Price: #{user_selection.price}"
                puts "URL: #{user_selection.url}"
                puts "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
        end
    end
end

#welcomeObject



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

def welcome
    puts <<-GREETING
    
    ██████╗ ███████╗███████╗████████╗███████╗███████╗██╗     ██╗     ███████╗██████╗ ███████╗
    ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔════╝██╔════╝██║     ██║     ██╔════╝██╔══██╗██╔════╝
    ██████╔╝█████╗  ███████╗   ██║   ███████╗█████╗  ██║     ██║     █████╗  ██████╔╝███████╗
    ██╔══██╗██╔══╝  ╚════██║   ██║   ╚════██║██╔══╝  ██║     ██║     ██╔══╝  ██╔══██╗╚════██║
    ██████╔╝███████╗███████║   ██║   ███████║███████╗███████╗███████╗███████╗██║  ██║███████║
    ╚═════╝ ╚══════╝╚══════╝   ╚═╝   ╚══════╝╚══════╝╚══════╝╚══════╝╚══════╝╚═╝  ╚═╝╚══════╝
                            The Best Selling Books You Must Read!
    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

    GREETING
end