LaptopHunt 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe56e16b7637d47e77fe71a0e0bdb33f5ce02294a98a14786606ade4033b5587
4
- data.tar.gz: 762f24b9885c6534dc04366b8501dc0c92a2a2e5b1b86f3f35f33f0e68c1ff9c
3
+ metadata.gz: 66e24416e3bf3b6d0bc41fecb8b524e5368ab1e52bb87733ae3c5bf9eb9d5b10
4
+ data.tar.gz: 7989ad6288cf3993534fb768fe139e869d553a1e4430c6a8021da78506b41eda
5
5
  SHA512:
6
- metadata.gz: 2d01482851af9fb7e4e8f5ee720ae01da2579d80db6580753d35147dbe8ee001ef7f0db924e2640096a0aea76ed4c45a11ed02718ea1bfde87cb1b4119546bbb
7
- data.tar.gz: 7d5b50cc136d3803dd46f73c923f3a377451ab161567b61c6ffd7c2377d96bdcd86118947d1f61d167fe8d5c232ed9e483a7f10a7b4cd6993f5c35f14dd45f76
6
+ metadata.gz: 59924a6b4606d031f23cf9049606813db217d199f9815bf66092e6a759fef8f59126b75a0d19f61a8c05f5f3472ce534da86ba1430cc98e11c8dbb9a5b854770
7
+ data.tar.gz: 475332d7ac1ee501c367a1deeee1a3edd53af3dea63a73df367f781c0b8780b52e527053f8f2cc79fa3669d4cd8f4e7ef74a4cc172bb8322e783faba54fb5032
data/bin/LaptopHunt CHANGED
@@ -1,3 +1,3 @@
1
1
  require_relative '../lib/LaptopHunt'
2
2
 
3
- LaptopHunt::CLI.new.run
3
+ LaptopHunt::CLI.new.call
@@ -1,7 +1,8 @@
1
1
  require 'pry'
2
2
  require 'nokogiri'
3
- require 'httparty'
3
+ require 'open-uri'
4
4
 
5
5
  require_relative '../lib/LaptopHunt/scraper.rb'
6
6
  require_relative '../lib/LaptopHunt/Laptop.rb'
7
+ require_relative '../lib/LaptopHunt/Apple.rb'
7
8
  require_relative '../lib/LaptopHunt/LaptopHunt.rb'
@@ -0,0 +1,25 @@
1
+ class LaptopHunt::Apple
2
+
3
+ attr_accessor :title, :price, :ratings, :shipping
4
+
5
+ @@all = []
6
+
7
+ def initialize(title, price, ratings)
8
+ @title = title
9
+ @price = price
10
+ @ratings = ratings
11
+ @shipping = shipping
12
+ self
13
+
14
+ end
15
+
16
+ def self.all
17
+ @@all
18
+ end
19
+
20
+ def self.find(id)
21
+ self.all[id-1]
22
+ end
23
+ end
24
+
25
+
@@ -1,30 +1,25 @@
1
1
 
2
2
  class LaptopHunt::Laptop
3
+
4
+ attr_accessor :title, :price, :ratings, :shipping
3
5
 
4
- @@all = []
6
+ @@all = []
5
7
 
6
- attr_accessor :name, :model, :price
8
+ def initialize(title, price, ratings)
9
+ @title = title
10
+ @price = price
11
+ @ratings = ratings
12
+ @shipping = shipping
13
+ self
7
14
 
15
+ end
8
16
 
9
- def initialize
17
+ def self.all
18
+ @@all
19
+ end
10
20
 
11
- @name = name
12
- @model = model
13
- @price = price
14
- @@all << self
21
+ def self.find(id)
22
+ self.all[id-1]
23
+ end
24
+ end
15
25
 
16
- end
17
-
18
- def self.all
19
- @@all
20
- end
21
-
22
- def model
23
- @model = page.css("ul.filterItem").text
24
- end
25
-
26
- #def cost
27
- # @price = page.css(".salePrice").text
28
- #end
29
-
30
- end
@@ -1,75 +1,117 @@
1
1
 
2
2
  class LaptopHunt::CLI
3
3
 
4
- #min = gets.input.to_i
5
- #max = gets.chomp.to_i
6
-
7
- #html = Nokogiri::HTML(open("http://www.tigerdirect.com/applications/category/category_slc.asp?Lprice=0.01&Hprice=#{max}&CatId=17"))
4
+ def call
5
+ run
6
+ end
7
+
8
8
 
9
+ def run
9
10
 
10
- #html.css('.itemName .salePrice').each do |div|
11
- #LaptopHunt::Laptop.new_from_index_page(div)
12
- #end
11
+ puts "Welcome to LaptopHunt!"
12
+ sleep(3)
13
+ puts "Let's help you find a laptop"
14
+ sleep(3)
15
+ selection
16
+ end
13
17
 
18
+ def selection
19
+ puts "Would you like to view A)Apple or B)PC laptops?"
20
+
21
+ answer = gets.strip.downcase
22
+
23
+ loop do
24
+ if answer == "a"
25
+ puts "Loading Macbooks..."
26
+ sleep(1)
27
+ apple_list
28
+ puts " "
29
+ puts "Which model would you like to view?"
30
+ puts "Enter 1-10"
31
+ input = gets.strip
32
+ mac = LaptopHunt::Laptop.find(input.to_i)
33
+ apple_details(mac)
34
+ break
35
+ elsif answer == "b"
36
+ puts "Loading laptop PC's..."
37
+ sleep(1)
38
+ laptop_list
39
+ puts " "
40
+ puts "Which model would you like to view?"
41
+ puts "Enter 1-10"
42
+ input = gets.strip
43
+ laptop = LaptopHunt::Laptop.find(input.to_i)
44
+
45
+ display_details(laptop)
46
+ break
47
+ else
48
+
49
+ puts "please select A or B"
50
+ answer = gets.chomp
14
51
 
52
+ end
53
+ end
54
+ end
15
55
 
16
- def newLaptop
17
- Nokogiri::HTML(open("http://www.tigerdirect.com/applications/category/category_slc.asp?CatId=4935"))
18
- end
19
-
56
+ def laptop_list
57
+ LaptopHunt::Scraper.scrape_pclaptop
20
58
 
21
- def initialize
22
- @model = model
23
- end
24
-
25
-
26
- def model
27
- @model = page.css("ul.filterItem").text
59
+ LaptopHunt::Scraper.laptop_list
60
+
61
+ LaptopHunt::Laptop.all[0, 10].each_with_index do |laptop, index|
62
+ puts "#{index+1}. #{laptop.title} "
63
+
64
+ end
28
65
  end
29
66
 
67
+ def display_details(laptop)
68
+ puts " "
69
+ puts " Laptop Details: #{laptop.title}"
70
+ puts " #{laptop.price} "
71
+ puts " #{laptop.ratings} "
72
+ puts " "
30
73
 
74
+ sleep(5)
75
+ more
76
+ end
31
77
 
32
- def run
33
- #LaptopHunt::Scraper.new.display_laptops
34
- puts "Welcome to LaptopHunt. Let's help you find a laptop!"
35
- sleep(2)
36
- search
37
- end
38
-
39
- def search
40
-
41
- puts "What is your price range?"
42
- sleep(1)
43
- puts "#{model}"
44
- end
78
+ def apple_list
79
+ LaptopHunt::Scraper.scrape_apple
80
+ LaptopHunt::Scraper.apple_list
81
+ LaptopHunt::Laptop.all[0, 10].each_with_index do |mac, index|
82
+ puts "#{index+1}. #{mac.title} "
83
+
45
84
  end
85
+ end
46
86
 
47
-
48
- #def self.selection
49
- #puts "Select from the list below to see more information"
50
- #details
51
- #end
87
+ def apple_details(mac)
88
+ puts " "
89
+ puts " Tablet Details: #{mac.title}"
90
+ puts " #{mac.price} "
91
+ puts " #{mac.ratings} "
92
+ puts " "
52
93
 
53
- def details
54
- puts "#{laptop.model}-----#{laptop.cost}"
55
- end
94
+ sleep(5)
95
+ more
96
+ end
56
97
 
57
- def more
58
- puts "Would you like to see more laptops (Y/N)?"
59
- answer = gets.chomp
60
-
61
- loop do
62
- if answer.include?("Y") || answer.include?("y")
63
- search
64
- break
65
- elsif answer.include?("N") || answer.include?("n")
66
- puts "Thank you and have a nice day!"
67
- break
68
- else
69
- puts "Please select Y or N"
70
- answer = gets.chomp
71
- end
98
+ def more
99
+ puts "What would you like to do now?"
100
+ puts "Type start over to start from the beginning or exit to close"
101
+ answer = gets.strip.downcase
102
+ loop do
103
+ if answer == "start over"
104
+ call
105
+ break
106
+ elsif answer == "exit"
107
+ puts "Have a nice day!"
108
+ exit
109
+ else puts "Please enter A or B"
110
+ more
72
111
  end
73
112
  end
74
113
 
75
114
 
115
+ end
116
+ end
117
+
@@ -1,19 +1,38 @@
1
- class LaptopHunt::Scraper
2
-
3
-
4
- def initialize
5
- url = "http://www.tigerdirect.com/applications/category/category_tlc.asp?CatId=17"
6
- page = Nokogiri::HTML(open(url))
7
- @laptops = []
8
- end
9
-
10
- def scrape_laptop
11
- price = page.css(".oldPrice")
12
- model = page.css(".itemName")
13
-
14
- @laptops.each do |laptops|
15
- i = @laptops.index(model)
16
- puts "#{price}-----#{model}"
17
- end
18
- end
19
- end
1
+
2
+
3
+ class LaptopHunt::Scraper
4
+
5
+ def self.scrape_pclaptop
6
+ @doc = Nokogiri::HTML(open("https://www.bestbuy.com/site/all-laptops/pc-laptops/pcmcat247400050000.c?id=pcmcat247400050000"))
7
+ @scrape = @doc.css("li.sku-item")
8
+ end
9
+
10
+ def self.laptop_list
11
+ @scrape.each do |item|
12
+ title = item.css("h4.sku-header").text.strip
13
+ price = item.css("div.priceView-customer-price span.sr-only").text
14
+ shipping = item.css("div.fulfillment-fulfillment-summary").text
15
+ ratings = item.css("div.c-ratings-reviews.v-small p.sr-only").text
16
+ laptop = LaptopHunt::Laptop.new(title, price, ratings)
17
+ LaptopHunt::Laptop.all << laptop
18
+ end
19
+ end
20
+
21
+ def self.scrape_apple
22
+ @doc2 = Nokogiri::HTML(open("https://www.bestbuy.com/site/all-laptops/macbooks/pcmcat247400050001.c?id=pcmcat247400050001"))
23
+ @apple = @doc2.css("li.sku-item")
24
+ end
25
+
26
+ def self.apple_list
27
+ @apple.each do |list|
28
+ title = list.css("h4.sku-header").text.strip
29
+ price = list.css("div.priceView-customer-price span.sr-only").text
30
+ ratings = list.css("div.c-ratings-reviews.v-small p.sr-only").text
31
+ model = list.css("div.sku-model span.sku-value").text
32
+ mac = LaptopHunt::Laptop.new(title, price, ratings)
33
+ LaptopHunt::Laptop.all << mac
34
+ end
35
+ end
36
+
37
+
38
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: LaptopHunt
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sarah Williams
@@ -103,6 +103,7 @@ extra_rdoc_files: []
103
103
  files:
104
104
  - bin/LaptopHunt
105
105
  - config/environment.rb
106
+ - lib/LaptopHunt/Apple.rb
106
107
  - lib/LaptopHunt/Laptop.rb
107
108
  - lib/LaptopHunt/LaptopHunt.rb
108
109
  - lib/LaptopHunt/scraper.rb