Class: PriceManager
- Inherits:
-
Object
- Object
- PriceManager
- Includes:
- Concerns::Mergable, Concerns::Printable, Concerns::Searchable, Concerns::Sortable, Concerns::Statistical
- Defined in:
- lib/price_manager.rb
Constant Summary collapse
- MENU =
["\n", "Available Actions:", "----------------------------------------------", "category -> View and Select Category", "view -> View Items in Category", "item -> Enter Search Item", "price -> View Price Information", "range -> View Items in Range", "pid -> View Item Advanced Info", "q -> Quit", "----------------------------------------------", "Please type in your selection", "----------------------------------------------"]
Instance Attribute Summary collapse
-
#category ⇒ Object
Returns the value of attribute category.
-
#item ⇒ Object
Returns the value of attribute item.
-
#max ⇒ Object
Returns the value of attribute max.
-
#menu ⇒ Object
readonly
Returns the value of attribute menu.
-
#min ⇒ Object
Returns the value of attribute min.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
-
#stats ⇒ Object
Returns the value of attribute stats.
-
#subcategory ⇒ Object
Returns the value of attribute subcategory.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #actions_menu ⇒ Object
- #call ⇒ Object
- #category_menu ⇒ Object
- #check_subcategory_menu ⇒ Object
-
#initialize(url) ⇒ PriceManager
constructor
A new instance of PriceManager.
- #process_category ⇒ Object
- #process_item ⇒ Object
- #process_pid ⇒ Object
- #process_price ⇒ Object
- #process_range ⇒ Object
- #subcategory_menu ⇒ Object
Methods included from Concerns::Mergable
#merge_item, #merge_price_manager_attr
Methods included from Concerns::Statistical
Methods included from Concerns::Printable
#print_basic_stats, #print_item_by_pid, #print_items_by_price, #print_items_in_category, #print_items_in_range
Methods included from Concerns::Sortable
#sort_by_location, #sort_by_price, #sort_by_price_in_range
Methods included from Concerns::Searchable
#get_link_from_key, #get_subcategory_info, #items_in_price_range, #items_with_price, #search_by_category, #search_by_pid, #search_by_type, #search_items
Constructor Details
#initialize(url) ⇒ PriceManager
Returns a new instance of PriceManager.
23 24 25 26 27 28 29 30 |
# File 'lib/price_manager.rb', line 23 def initialize(url) @url = url puts "OK, we are working with #{@url}" sleep 1 @site = CL_Scraper.new(@url) @site.scrape_for_sale_categories @stats = {} end |
Instance Attribute Details
#category ⇒ Object
Returns the value of attribute category.
2 3 4 |
# File 'lib/price_manager.rb', line 2 def category @category end |
#item ⇒ Object
Returns the value of attribute item.
2 3 4 |
# File 'lib/price_manager.rb', line 2 def item @item end |
#max ⇒ Object
Returns the value of attribute max.
2 3 4 |
# File 'lib/price_manager.rb', line 2 def max @max end |
#menu ⇒ Object (readonly)
Returns the value of attribute menu.
3 4 5 |
# File 'lib/price_manager.rb', line 3 def @menu end |
#min ⇒ Object
Returns the value of attribute min.
2 3 4 |
# File 'lib/price_manager.rb', line 2 def min @min end |
#pid ⇒ Object
Returns the value of attribute pid.
2 3 4 |
# File 'lib/price_manager.rb', line 2 def pid @pid end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
3 4 5 |
# File 'lib/price_manager.rb', line 3 def site @site end |
#stats ⇒ Object
Returns the value of attribute stats.
2 3 4 |
# File 'lib/price_manager.rb', line 2 def stats @stats end |
#subcategory ⇒ Object
Returns the value of attribute subcategory.
2 3 4 |
# File 'lib/price_manager.rb', line 2 def subcategory @subcategory end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/price_manager.rb', line 3 def url @url end |
Instance Method Details
#actions_menu ⇒ Object
58 59 60 61 |
# File 'lib/price_manager.rb', line 58 def MENU.each{|| puts "#{}"} gets.chomp end |
#call ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/price_manager.rb', line 32 def call process_category run = true while run case when "category" process_category when "view" print_items_in_category when "item" process_item when "price" process_price when "range" process_range when "pid" process_pid when "debug" binding.pry #uncomment this line and require 'pry' to allow debug session when "q" run = false end end end |
#category_menu ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/price_manager.rb', line 104 def puts "\n" puts "Available 'for sale' categories are:" puts "----------------------------------------------" @site..each_key{|key| puts key} puts "----------------------------------------------" puts "Enter the category you want to browse" puts "----------------------------------------------" @category = gets.strip.downcase unless @site..has_key?(@category) puts "Category: #{@category} not found! Please check the spelling." sleep 1 end end |
#check_subcategory_menu ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/price_manager.rb', line 121 def list = ["auto parts", "bikes", "boats", "cars+trucks", "computers", "motorcycles"] if list.include?(@category) @site.(get_link_from_key) else get_link_from_key end end |
#process_category ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/price_manager.rb', line 63 def process_category #@site.scrape_category(category_menu) @site.scrape_page() #Better for testing. Item.create_from_collection(@site.all) merge_price_manager_attr #Set item category and url if they are not set. print_items_in_category process_item end |
#process_item ⇒ Object
72 73 74 75 76 77 |
# File 'lib/price_manager.rb', line 72 def process_item puts "Please Enter your sale item:" @item = gets.chomp.downcase search_by_type process_price end |
#process_pid ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/price_manager.rb', line 79 def process_pid puts "Please Enter the PID:" @pid = gets.chomp if search_by_pid != [] Item.merge_item(@pid, @site.scrape_by_pid(search_by_pid.link)) print_item_by_pid else puts "PID: #{@pid} unavailable in #{@category}" print_item_by_pid end end |
#process_price ⇒ Object
91 92 93 94 |
# File 'lib/price_manager.rb', line 91 def process_price print_items_by_price print_basic_stats end |
#process_range ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/price_manager.rb', line 96 def process_range puts "Enter a minimum price" @min = gets.chomp.to_i puts "Enter a maximum price" @max = gets.chomp.to_i print_items_in_range end |
#subcategory_menu ⇒ Object
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 |
# File 'lib/price_manager.rb', line 131 def puts "----------------------------------------------" puts "Available categories in #{@category} are:" puts "----------------------------------------------" @site..each_key{|key| puts key} puts "----------------------------------------------" puts "\n" puts "Enter the subcategory you want to browse" puts "----------------------------------------------" @subcategory = gets.strip unless @site..has_key?(@subcategory) puts "******************************************************************" puts "Subcategory: #{@subcategory} not found! Please check the spelling." puts "******************************************************************" sleep 1 #pause so user can see warning else puts "\n" puts "Please type in a selection from the following:" puts "----------------------------------------------" get_subcategory_info.each_key{|key| puts key.downcase} puts "----------------------------------------------" choice = gets.strip.upcase @url + get_subcategory_info.fetch(choice) end end |