class SteamDailyDeals::CLI
CLI
class
Public Instance Methods
add_deal_details()
click to toggle source
# 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
call()
click to toggle source
# 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_deals()
click to toggle source
# 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_deals()
click to toggle source
# 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
show_deal(index)
click to toggle source
# 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