dslr_shop 0.1.0 → 1.0.0

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
  SHA1:
3
- metadata.gz: 1c114830324aca7cc1e4670feb9f113604232d58
4
- data.tar.gz: d565f1f3f46f8e146866ca4f52f9b3d51d7c7e6e
3
+ metadata.gz: 8203cac3b029ccbb6442b73c7063540c756216cb
4
+ data.tar.gz: e55f45bd272db88c47f7b117f07b12d497580d22
5
5
  SHA512:
6
- metadata.gz: 33e84872e5c206985c08c3cc9ed7589dd2dd4e08128fc855c0b8857ccc935ca48db0a77d67330a41ae061afd860a65b724c1a01ed5c84fd7e00064606a421f91
7
- data.tar.gz: 2f945018d8222d6bcc8f3a026e728b64db92515d5152a7ed456fb01758d4b75c56fe2f51c7e2d2ae9264764f5de8dae6a508f580dea0455a37fdf9829073294b
6
+ metadata.gz: fd5d2bcf9e97fd6041bc32cbc7f558a9452fa696c5f4f88157b1099eae3df68009781fdf1abffdb40a4a8e5504a6787dbd10221ed8eb807196936b44e96e0e11
7
+ data.tar.gz: 3ed1c49206ea77fb8c8057c0cde184d8044a8d2cbb2b49ab27116c8b2474a825ea8c2a5645a88078aa71031da9a7483450a90a123e9c39463955065f342519c6
data/dslr_shop.gemspec CHANGED
@@ -26,15 +26,15 @@ Gem::Specification.new do |spec|
26
26
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
27
  f.match(%r{^(test|spec|features)/})
28
28
  end
29
- # spec.bindir = "exe"
29
+ spec.bindir = "bin"
30
30
  spec.executables << "dslr_shop"
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.add_development_dependency "bundler", "~> 1.14"
33
+ spec.add_runtime_dependency "bundler", "~> 1.14"
34
34
  spec.add_development_dependency "rake", "~> 10.0"
35
35
  spec.add_development_dependency "rspec", "~> 3.0"
36
- spec.add_development_dependency "nokogiri", ">= 0"
36
+ spec.add_runtime_dependency "nokogiri", ">= 0"
37
37
  spec.add_development_dependency "pry", ">= 0"
38
- spec.add_development_dependency "require_all"
39
- spec.add_development_dependency "colorize"
38
+ spec.add_runtime_dependency "require_all"
39
+ spec.add_runtime_dependency "colorize"
40
40
  end
@@ -7,25 +7,24 @@ class DslrShop::Camera
7
7
  @@all
8
8
  end
9
9
 
10
- def initialize(camera_hash)
11
- camera_hash.each {|key, value|
12
- self.send(("#{key}="),value)
13
- }
10
+ def initialize(brand = nil, name = nil, availability = nil, price = nil, url = nil)
11
+ @brand = brand
12
+ @name = name
13
+ @availability = availability
14
+ @price = price
15
+ @url = url
14
16
  @@all << self
15
17
  end
16
18
 
17
- def self.create_from_collection(camera_collection)
18
- # camera_collection=> array of camera_hashes
19
- camera_collection.each {|camera_hash|
20
- self.new(camera_hash)
21
- }
22
- end
23
-
24
- def add_attributes(attribute_hash)
25
- attribute_hash.each {|key, value|
26
- self.send(("#{key}="), value)
27
- }
19
+ # def self.create_from_collection(camera_collection)
20
+ # # camera_collection=> array of camera_hashes
21
+ # camera_collection.each {|camera_hash|
22
+ # self.new(camera_hash)
23
+ # }
24
+ # end
28
25
 
26
+ def add_attributes
27
+ DslrShop::Scraper.scrape_from_detail(self)
29
28
  end
30
29
 
31
30
  end
data/lib/dslr_shop/cli.rb CHANGED
@@ -4,22 +4,18 @@ class DslrShop::CLI
4
4
 
5
5
  def run
6
6
  make_cameras
7
- add_attributes_from_detail
7
+ # add_attributes_from_detail
8
8
  list_cameras
9
9
  display_menu
10
10
  goodbye
11
11
  end
12
12
 
13
13
  def make_cameras
14
- camera_collection = DslrShop::Scraper.scrape_from_list(LIST_PAGE)
15
- DslrShop::Camera.create_from_collection(camera_collection)
14
+ DslrShop::Scraper.scrape_from_list(LIST_PAGE)
16
15
  end
17
16
 
18
- def add_attributes_from_detail
19
- DslrShop::Camera.all.each {|camera|
20
- camera_attributes = DslrShop::Scraper.scrape_from_detail(camera.url)
21
- camera.add_attributes(camera_attributes)
22
- }
17
+ def add_attributes_from_detail(camera)
18
+ camera.add_attributes
23
19
  end
24
20
 
25
21
  def list_cameras
@@ -56,6 +52,7 @@ class DslrShop::CLI
56
52
  end
57
53
 
58
54
  if index.to_i>0
55
+ self.add_attributes_from_detail(camera_list[index.to_i - 1])
59
56
  puts "#{camera_list[index.to_i - 1].brand.upcase} #{camera_list[index.to_i - 1].name}".colorize(:color => :light_blue, :background => :light_yellow)
60
57
  puts "Rank: #{index}".colorize(:color => :light_blue, :background => :light_yellow)
61
58
  puts "Camera Type: #{camera_list[index.to_i - 1].type}".colorize(:color => :light_blue, :background => :light_yellow)
@@ -3,29 +3,28 @@ class DslrShop::Scraper
3
3
  def self.scrape_from_list(list_url)
4
4
  doc = Nokogiri::HTML(open(list_url))
5
5
  camera_nodes = doc.search("div.item.clearfix")
6
- camera_nodes.map {|camera|
7
- {
8
- brand: camera.search("div.desc-zone.zone h3 a span")[0].text,
9
- name: camera.search("div.desc-zone.zone h3 a span")[1].text.chomp(" (Body Only)"),
10
- availability: camera.search("p.scAvailabilityTri span").text.strip,
11
- price: camera.search("div.atc-price p span.price").text.strip,
12
- url: camera.search("div.desc-zone.zone h3 a").attr('href').text
13
- }
6
+ camera_nodes.map {|camera_node|
7
+ camera = DslrShop::Camera.new
8
+ camera.brand = camera_node.search("div.desc-zone.zone h3 a span")[0].text
9
+ camera.name = camera_node.search("div.desc-zone.zone h3 a span")[1].text.chomp(" (Body Only)")
10
+ camera.availability = camera_node.search("p.scAvailabilityTri span").text.strip
11
+ camera.price = camera_node.search("div.atc-price p span.price").text.strip
12
+ camera.url = camera_node.search("div.desc-zone.zone h3 a").attr('href').text
14
13
  }
15
14
  end
16
15
 
17
- def self.scrape_from_detail(detail_url)
18
- doc = Nokogiri::HTML(open(detail_url))
19
- camera_attr = {}
20
- camera_attr[:discount] = doc.search("div.pPrice p span").text.strip
21
- camera_attr[:type] = doc.search("div.product-highlights ul li")[0].text
16
+ def self.scrape_from_detail(camera)
17
+ doc = Nokogiri::HTML(open(camera.url))
18
+
19
+ camera.discount = doc.search("div.pPrice p span").text.strip
20
+ camera.type = doc.search("div.product-highlights ul li")[0].text
22
21
  # begin
23
- camera_attr[:style] = doc.search("div.items-group p span")[0].text if doc.search("div.items-group p span")[0]
22
+ camera.style = doc.search("div.items-group p span")[0].text if doc.search("div.items-group p span")[0]
24
23
  # rescue StandardError
25
24
  # binding.pry
26
25
  # end
27
- camera_attr[:rewards] = doc.search("div.acTwoPercent a").text.gsub(/\s+[a-z]*$/, "") if doc.search("div.acTwoPercent a").size>0
28
- camera_attr
26
+ camera.rewards = doc.search("div.acTwoPercent a").text.gsub(/\s+[a-z]*$/, "") if doc.search("div.acTwoPercent a").size>0
27
+ camera
29
28
  end
30
29
 
31
30
  # This gem provides an interactive CLI to view the top 24 DSLR cameras as rated by the photography store B & H Photography's website.
@@ -1,3 +1,3 @@
1
1
  module DslrShop
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dslr_shop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sarjumulmi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-29 00:00:00.000000000 Z
11
+ date: 2017-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -17,7 +17,7 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.14'
20
- type: :development
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
@@ -59,7 +59,7 @@ dependencies:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- type: :development
62
+ type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
@@ -87,7 +87,7 @@ dependencies:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
- type: :development
90
+ type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
@@ -101,7 +101,7 @@ dependencies:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
- type: :development
104
+ type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements: