Class: PopularDeals::CLI
- Inherits:
-
Object
- Object
- PopularDeals::CLI
- Defined in:
- lib/popular_deals/cli.rb
Overview
CLI Controller
Instance Attribute Summary collapse
-
#product_url ⇒ Object
Returns the value of attribute product_url.
Instance Method Summary collapse
- #call ⇒ Object
- #disply_deal(input, product_url) ⇒ Object
- #goodbye ⇒ Object
- #list_deals ⇒ Object
- #menu ⇒ Object
Instance Attribute Details
#product_url ⇒ Object
Returns the value of attribute product_url.
4 5 6 |
# File 'lib/popular_deals/cli.rb', line 4 def product_url @product_url end |
Instance Method Details
#call ⇒ Object
6 7 8 9 |
# File 'lib/popular_deals/cli.rb', line 6 def call list_deals end |
#disply_deal(input, product_url) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/popular_deals/cli.rb', line 47 def disply_deal(input, product_url) @deal = PopularDeals::NewDeals.deal_page(input, product_url) keys = @deal.keys puts "" puts "Deal:".yellow puts "#{@deal[keys[0]]}" puts "" puts "Description:".yellow puts "#{@deal[keys[1]]}" puts "" puts "To lock this deal, please visit:".yellow puts "#{@deal[keys[2]]}" puts "-----------------------------------------------------------------------------------------------------------" puts "" end |
#goodbye ⇒ Object
63 64 65 66 67 |
# File 'lib/popular_deals/cli.rb', line 63 def goodbye puts "" puts "Come back again for more deals. Have a great day!".light_blue puts "" end |
#list_deals ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/popular_deals/cli.rb', line 11 def list_deals puts "Today's popular deals are:" @deals = PopularDeals::NewDeals.new_deals @deals.each do |info| info.each.with_index(1) do |deal, i| puts "#{i}. #{deal.title} - deal popularity: #{deal.deal_rating}." end end end |
#menu ⇒ Object
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 |
# File 'lib/popular_deals/cli.rb', line 21 def input = nil while input != "exit" puts "" puts "Enter the number of deal you would like more info on or type Exit".light_blue puts "" input = gets.strip.downcase puts "" if input.to_i > 0 && input.to_i <= 20 puts "" puts "-----------------------------------------------------------------------------------------------------------" puts "Please see below details of deal no. #{input}".yellow.underline disply_deal(input, product_url) elsif input == "list" list_deals elsif input == "exit" goodbye else puts "Don't understand your command. Type list to see the list or exit".colorize(:color => :white, :background => :red) puts "" end end end |