Class: SteamDailyDeals::CLI

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

Overview

CLI class

Instance Method Summary collapse

Instance Method Details

#add_deal_detailsObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/steam_daily_deals/cli.rb', line 72

def add_deal_details
  line_count = 0

  SteamDailyDeals::Deal.all.each do |deal|
    info = SteamDailyDeals::Scraper.scrape_deal_page(deal.app_url)
    deal.add_deal_information(info)
    print '='.red * (160 / SteamDailyDeals::Deal.all.uniq.count)
    line_count += (160 / SteamDailyDeals::Deal.all.uniq.count)
  end

  print '='.red * (160 - line_count)

  vertical_spacing 1
end

#callObject



10
11
12
13
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
# File 'lib/steam_daily_deals/cli.rb', line 10

def call
  extend CommandLineReporter

  # This part here looks pretty ugly with the heredoc, but I'm not sure of a
  # better way to make sure I have all of this text centered and keep the look
  # I was working toward.  It can be completely removed and just made to have
  # a regular "Welcome to the Steam Daily Deals" line, but this was an astetic
  # choice
  puts <<-DOC

                                          ad88888ba  888888888888  88888888888         db         88b           d88
                                         d8"     "8b      88       88                 d88b        888b         d888
                                         Y8,              88       88                d8'`8b       88`8b       d8'88
                                         `Y8aaaaa,        88       88aaaaa          d8'  `8b      88 `8b     d8' 88
                                           `"""""8b,      88       88"""""         d8YaaaaY8b     88  `8b   d8'  88
                                                 `8b      88       88             d8""""""""8b    88   `8b d8'   88
                                         Y8a     a8P      88       88            d8'        `8b   88    `888'    88
                                          "Y88888P"       88       88888888888  d8'          `8b  88     `8'     88
                                                    ____          _  _           ____                _
                                                   |  _ \\   __ _ (_)| | _   _   |  _ \\   ___   __ _ | | ___
                                                   | | | | / _` || || || | | |  | | | | / _ \\ / _` || |/ __|
                                                   | |_| || (_| || || || |_| |  | |_| ||  __/| (_| || |\\__ \\
                                                   |____/  \\__,_||_||_| \\__, |  |____/  \\___| \\__,_||_||___/
                                                                         |___/

  DOC

  horizontal_rule(width: 160, color: 'red')
  header(title: 'Please wait while we load todays daily deals', color: 'red', align: 'center', width: 160, spacing: 0)
  make_deals
  header(title: 'This may take a minute to load everything', color: 'red', align: 'center', width: 160, spacing: 0)
  header(title: 'Progress:', color: 'red', align: 'center', width: 160, spacing: 0)
  add_deal_details
  horizontal_rule(width: 160, color: 'red')
  vertical_spacing 1
  menu
end

#list_dealsObject



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
114
115
# File 'lib/steam_daily_deals/cli.rb', line 87

def list_deals
  extend CommandLineReporter

  table(border: true) do
    row do
      column('No', width: 6, align: 'center')
      column('Title', width: 94, padding: 2, align: 'center')
      column('Price', width: 16, align: 'center')
      column('Status', width: 31, align: 'center')
    end
    deals = SteamDailyDeals::Deal.all

    deals.each.with_index(1) do |deal, i|
      row do
        column(i.to_s, color: 'cyan')
        column(deal.name)
        if deal.final_price.nil? || deal.final_price == ''
          column('Free', color: 'red')
        else
          column(deal.final_price, color: 'red')
        end
        column(deal.availibility, color: 'green')
      end
    end
  end

  puts 'Please enter the number of the deal you wish to see more information about'
  print 'You may also type list to see the list again or exit to quit: '
end

#make_dealsObject



67
68
69
70
# File 'lib/steam_daily_deals/cli.rb', line 67

def make_deals
  deals_array = SteamDailyDeals::Scraper.scrape_index_page.uniq
  SteamDailyDeals::Deal.create_from_collection(deals_array)
end


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

def menu
  print "Please type in list to get a list of today's deals on steam or type exit: ".cyan
  input = nil
  until input == 'exit'
    input = gets.strip.downcase

    if input.to_i.between?(1, SteamDailyDeals::Deal.all.count)
      show_deal(input.to_i)
    elsif input == 'list'
      list_deals
    elsif input == 'exit'
      puts 'See you tomorrow!'.green
    else
      puts "I'm sorry that was not a valid entry".red
      print "Please type list to get a list of today's deals or type exit to quit the program: ".cyan
    end
  end
end

#show_deal(index) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/steam_daily_deals/cli.rb', line 117

def show_deal(index)
  extend CommandLineReporter

  vertical_spacing 2

  deal_details = SteamDailyDeals::Deal.find_deal(index)

  # Deal Title and Price
  table(border: true) do
    row do
      column(deal_details.name, width: 143, align: 'center', color: 'cyan')
      if deal_details.final_price.nil? || deal_details.final_price == ''
        column('Free', width: 10, align: 'center', color: 'red')
      else
        column(deal_details.final_price, width: 10, align: 'center', color: 'red')
      end
    end
  end

  # Deal Description
  table(border: true) do
    row do
      column(deal_details.description, width: 156)
    end
  end

  # Details
  table(border: true) do
    unless deal_details.release_date.nil?
      row do
        column('Release Date', width: 53, color: 'cyan')
        column(deal_details.release_date, width: 100)
      end
    end

    unless deal_details.recent_rating.nil?
      review_text = "#{deal_details.recent_rating} #{deal_details.recent_reviews}"
      row do
        column('Recent Reviews', width: 53, color: 'cyan')
        if review_text.downcase.include?('positive')
          column(review_text, width: 100, color: 'green')
        elsif review_text.downcase.include?('negative')
          column(review_text, width: 100, color: 'red')
        else
          column(review_text, width: 100, color: 'yellow')
        end
      end
    end

    unless deal_details.overall_rating.nil?
      review_text = "#{deal_details.overall_rating} #{deal_details.total_reviews}"
      row do
        column('Overall Reviews', width: 53, color: 'cyan')
        if review_text.downcase.include?('positive')
          column(review_text, width: 100, color: 'green')
        elsif review_text.downcase.include?('negative')
          column(review_text, width: 100, color: 'red')
        else
          column(review_text, width: 100, color: 'yellow')
        end
      end
    end

    row do
      column('Popular Tags', width: 53, color: 'cyan')
      column(deal_details.popular_tags.join(", "), width: 100)
    end
  end

  print "Please type list to get a list of today's deals or type exit to quit the program: ".cyan
end