Class: RumbleBundle::CLI
- Inherits:
-
Object
- Object
- RumbleBundle::CLI
- Defined in:
- lib/rumble_bundle/cli.rb
Instance Method Summary collapse
- #display_bundle(bundle) ⇒ Object
- #display_product(product) ⇒ Object
- #filter(input) ⇒ Object
- #help ⇒ Object
- #query ⇒ Object
- #quit ⇒ Object
- #start ⇒ Object
Instance Method Details
#display_bundle(bundle) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/rumble_bundle/cli.rb', line 98 def display_bundle(bundle) puts "---------------------------------------------------------------" puts "#{bundle.name} (#{bundle.url})" puts "#{bundle.total_msrp}!" puts "" puts "Supports:" bundle.charities.each do |c| print " #{c}" puts "," end puts " or a Charity of Your Choice" puts "", "" bundle.tiers.each do |tier| puts tier, "" bundle.products.each do |product| if product.tier == tier display_product(product) end end puts "" end puts "---------------------------------------------------------------" query end |
#display_product(product) ⇒ Object
124 125 126 127 128 129 130 131 132 |
# File 'lib/rumble_bundle/cli.rb', line 124 def display_product(product) print " #{product.name}" print " (#{product.platforms.join(", ")})" if product.platforms.any? print " (DRM-Free!)" if product.drm_free print " (w/Steam Key!)" if product.steam_key puts "" puts " #{product.subtitle}" if product.subtitle puts "" end |
#filter(input) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rumble_bundle/cli.rb', line 53 def filter(input) filters = %w[drm-free steam-key windows mac linux android] valid = filters & input.split if valid.any? filtered = RumbleBundle::Product.all.collect{|p| p} valid.each do |filter| case filter when 'windows','mac','linux','android' filtered.delete_if{|p| ! p.platforms.include?(filter.capitalize)} when 'drm-free' filtered.delete_if{|p| ! p.drm_free} when 'steam-key' filtered.delete_if{|p| ! p.steam_key} end end if filtered.any? puts "" puts "Results for: #{valid}" puts "---------------------------------------------------------------" filtered.collect{|p| p.bundle }.uniq.each do |bundle| puts "#{bundle.name} (#{bundle.url})" puts "" filtered.each{|p| display_product(p) if p.bundle == bundle} puts "" end puts "---------------------------------------------------------------" else puts "" puts "Sorry! No results for: #{valid}" puts "---------------------------------------------------------------" puts "---------------------------------------------------------------" end else puts "" puts "Sorry! Please enter a valid number or command." query end query end |
#help ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/rumble_bundle/cli.rb', line 134 def help puts " ---------------------------------------------------------------\n You can enter a filter to list all products matching that filter.\n You can combine multiple filters in a space-separated list.\n\n e.g. 'drm-free linux'\n\n drm-free\n steam-key\n windows\n mac\n linux\n android\n\n Press any key to continue.\n ---------------------------------------------------------------\n HEREDOC\n STDIN.getch\n query\nend\n" |
#query ⇒ Object
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 47 48 49 50 51 |
# File 'lib/rumble_bundle/cli.rb', line 15 def query bundles = RumbleBundle::Bundle.all puts "" puts "Enter a bundle's number to learn more, or enter 'help' for more commands." puts "Enter 'quit' to leave the program." puts "" bundles.each.with_index(1) do |bundle, i| puts "[#{i}] #{bundle.name}" end puts "" print " " input = gets.strip.downcase puts "" if input.to_i.between?(1, bundles.length) display_bundle(bundles[input.to_i - 1]) elsif input.to_i < 0 || input.to_i > bundles.length puts "" puts "Sorry! Please enter a valid number or command." query else case input when 'help' help when 'quit' quit else filter(input) end end end |
#quit ⇒ Object
156 157 158 |
# File 'lib/rumble_bundle/cli.rb', line 156 def quit exit end |
#start ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/rumble_bundle/cli.rb', line 3 def start puts "" puts "Fetching data from HumbleBundle.com..." puts "" RumbleBundle::Scraper.new.crawl_site query end |