LaptopHunt 0.1 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/LaptopHunt +1 -1
- data/config/environment.rb +2 -1
- data/lib/LaptopHunt/Apple.rb +25 -0
- data/lib/LaptopHunt/Laptop.rb +17 -22
- data/lib/LaptopHunt/LaptopHunt.rb +96 -54
- data/lib/LaptopHunt/scraper.rb +38 -19
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66e24416e3bf3b6d0bc41fecb8b524e5368ab1e52bb87733ae3c5bf9eb9d5b10
|
4
|
+
data.tar.gz: 7989ad6288cf3993534fb768fe139e869d553a1e4430c6a8021da78506b41eda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59924a6b4606d031f23cf9049606813db217d199f9815bf66092e6a759fef8f59126b75a0d19f61a8c05f5f3472ce534da86ba1430cc98e11c8dbb9a5b854770
|
7
|
+
data.tar.gz: 475332d7ac1ee501c367a1deeee1a3edd53af3dea63a73df367f781c0b8780b52e527053f8f2cc79fa3669d4cd8f4e7ef74a4cc172bb8322e783faba54fb5032
|
data/bin/LaptopHunt
CHANGED
data/config/environment.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'pry'
|
2
2
|
require 'nokogiri'
|
3
|
-
require '
|
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
|
+
|
data/lib/LaptopHunt/Laptop.rb
CHANGED
@@ -1,30 +1,25 @@
|
|
1
1
|
|
2
2
|
class LaptopHunt::Laptop
|
3
|
+
|
4
|
+
attr_accessor :title, :price, :ratings, :shipping
|
3
5
|
|
4
|
-
|
6
|
+
@@all = []
|
5
7
|
|
6
|
-
|
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
|
-
|
17
|
+
def self.all
|
18
|
+
@@all
|
19
|
+
end
|
10
20
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
def call
|
5
|
+
run
|
6
|
+
end
|
7
|
+
|
8
8
|
|
9
|
+
def run
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
56
|
+
def laptop_list
|
57
|
+
LaptopHunt::Scraper.scrape_pclaptop
|
20
58
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
94
|
+
sleep(5)
|
95
|
+
more
|
96
|
+
end
|
56
97
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
+
|
data/lib/LaptopHunt/scraper.rb
CHANGED
@@ -1,19 +1,38 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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.
|
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
|