Class: DailyTrending::Cli

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

Instance Method Summary collapse

Instance Method Details

#app_info(app) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/daily_trending/cli.rb', line 45

def app_info(app)
    DailyTrending::Scraper.new.scrape_app(app)
    puts <<-DOC
            #{app.title.upcase.colorize(:blue)}
              Developers: #{app.dev}
                Content For: #{app.con_rating}
                    Rated By: #{app.rate_cnt}

    DOC
          puts "DESCRIPTION:".colorize(:red)
    puts <<-DOC

        #{app.description}

    Get App At: #{app.app_url.colorize(:red)}
    More Apps By #{app.dev}: #{app.dev_url.colorize(:red)}

    DOC
    # open_browser(app)

  puts "  Type 'list' to see apps again or 'exit' to leave"
    menu
end

#callObject



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

def call
  list_apps
  menu
end

#goodbyeObject



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

def goodbye
  puts "See you next time!!"
  exit
end

#list_appsObject



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

def list_apps
  s = "******".colorize(:red)
  puts ""
  puts "  #{s}"+"New And Updated Apps!"+s
  puts ""
  DailyTrending::Scraper.new.scrape_index_page
  DailyTrending::App.all.each.with_index(1) do |app, i|
    puts <<-DOC
    #{i}. #{app.title.colorize(:blue)}
      #{app.rating}        Cost: #{app.price}

    DOC
  end
  puts ""
  puts "Enter the number of the app you'd like more info on, or type exit"
end


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/daily_trending/cli.rb', line 26

def menu
  input = nil
  until input == 'exit'
    input = gets.strip.downcase

    if input.to_i > 0 && input.to_i <= DailyTrending::App.all.size
      app_info(DailyTrending::App.find(input))
    elsif input == 'list'
      list_apps
    elsif input == 'exit'
      goodbye
    else
      puts "  #{input} not an option, type list or exit" unless input == 'exit'
    end
  end
end