Class: Toogle::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



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

def call
    show_title_intro
    creation
    get_and_show_data
    perform_new_search?
end

#creationObject



43
44
45
# File 'lib/toogle/cli.rb', line 43

def creation
    Toogle::Query.create
end

#get_and_show_dataObject



47
48
49
50
51
52
53
54
55
# File 'lib/toogle/cli.rb', line 47

def get_and_show_data
    Toogle::Query.all.each do |ele| 
        puts "\n#{ele.title.green}"
        puts "_".yellow * ele.title.length
        puts "\n#{ele.link.blue}"
        puts ele.description.red
        puts
    end
end

#goodbyeObject



70
71
72
73
74
# File 'lib/toogle/cli.rb', line 70

def goodbye
    puts "\nSee you soon!"
    puts
    exit!
end

#perform_new_search?Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/toogle/cli.rb', line 57

def perform_new_search?
    while true
        puts "\nWould you like to enter a new search?(Y/n)"
        input = gets.chomp.downcase
        if input == 'y'
            creation 
            get_and_show_data
        elsif input == 'n' || input != 'y'
            goodbye
        end
    end
end

#scraper_gets_user_infoObject



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

def 
    scraper = Toogle::Scraper.new
    while true 
        puts "\nEnter your".red + " search term/s".green
        print "\n> ".green
        query = gets.chomp.to_s.downcase
        if query == ""
            puts "\nSorry, you must enter a valid search, or if you wish to exit type 'exit' or press Control C"
        elsif query == 'exit'
            goodbye
        else
            print "\nHow many pages would you like for you search, choose between 1 and 5? "
            pages = gets.chomp.to_i 
            if !(1..5).include?(pages)
                puts "\nSorry, you can only search within the first 5 pages"
            elsif pages.to_s == 'exit'
                goodbye
            else
                break
            end
        end
    end
    puts "\nLoading".yellow + " search".green + " results".blue + " ...".red
    scraper.query_data(query, pages)
end

#show_title_introObject



10
11
12
13
14
15
# File 'lib/toogle/cli.rb', line 10

def show_title_intro
    font_art = Toogle::FontArt
    font_art.line_1
    font_art.get_font_art
    font_art.line_2
end