price_pulse 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4794648ef8458ceddf145a60327ed6932756bbff445d53f36d8755312aa5a90d
4
- data.tar.gz: ce947c61ec17efc60f61d66afb434804344cc519f1ec49001a5ab994ba864e36
3
+ metadata.gz: 9e1ebce42ecca784e3b869654fb815a8117ae153cea15b3e30b0b7c11fe3c79c
4
+ data.tar.gz: 9c858447bf6bea13af12e345bf1431b100b22bb05840347d04b412ced0cce077
5
5
  SHA512:
6
- metadata.gz: 92f7565f059ad0c63e645d3171b8d6ae0a7865e65790925de7e793b2048283cd8cd2e5f2333f40c6e15054473ffaf0604c840b08fc131bc5efa960d53489e117
7
- data.tar.gz: d8ad72b348c44b84afbc3d9564e133efbd77f53d453f933c7c9fdbd9466e1e438bac405e092c6c9dde970812bd47db95223da1936acb028a74d5762017671d57
6
+ metadata.gz: 385c90b62a20ad17707c5619a52f3ac9b2163424764e5df3e7e31d270870e29bf07f45161e94a5ce31414269a9d50184549229804e10c7dbfc461571b690456c
7
+ data.tar.gz: 86a1d9a4d8e307ed6b21c970da9a1b7f3776b12168ff1bcc001ea3dd78de8122e9d1f59e5574c09e08cc3b949608e8d1bb40f069687f6a122aca0bc637fa2d08
@@ -1,76 +1,74 @@
1
- # frozen_string_literal: true
2
-
3
- require "net/http"
4
- require "nokogiri"
5
- require "openssl"
6
-
7
- module PricePulse
8
- class Tracker
9
- def initialize(items)
10
- @items = items
11
- end
12
-
13
- def compare_prices(item_name)
14
- target_price = @items[item_name]
15
- return "Item not found." unless target_price
16
-
17
- full_prices = get_prices(item_name)
18
-
19
- # FIX: Create a numerical hash by filtering out non-price keys (like the Title string)
20
- numerical_prices = full_prices.reject { |key, value| key == "Source (Title)" }
21
-
22
- best_price = numerical_prices.values.min
23
- best_shop = numerical_prices.key(best_price)
24
-
25
- report = ["--- Tracking: #{item_name} (Target: $#{target_price}) ---"]
26
-
27
- # Display all data, including the Title string, correctly formatted
28
- full_prices.each do |shop, price|
29
- display_price = price.is_a?(String) ? price : "$#{price}"
30
- report << " - #{shop} price: #{display_price}"
31
- end
32
-
33
- if best_price < target_price
34
- report << " => **DEAL!** Below target price of $#{target_price}"
35
- else
36
- report << " => Price is currently $#{best_price}, waiting for a better deal."
37
- end
38
- report << "Best Current Price Found: $#{best_price} at #{best_shop}"
39
- report.join("\n")
40
- end
41
-
42
- private
43
-
44
- def get_prices(item_name)
45
- # 1. Define the URL for the item (live fetching from Wikipedia)
46
- url_base = "https://en.wikipedia.org/wiki/Coffee_maker"
47
- uri = URI.parse(url_base)
48
-
49
- # 2. Execute the live web request, bypassing the certificate error
50
- http = Net::HTTP.new(uri.host, uri.port)
51
- http.use_ssl = true
52
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
53
- response = http.request_get(uri.request_uri)
54
-
55
- # 3. Define the simulated HTML body for price parsing
56
- html_body = "<html><body><div id='price'>$#{item_name == 'Coffee Maker' ? 170.0 : 85.0}</div></body></html>"
57
-
58
- # 4. Use Nokogiri to parse the simulated HTML (using html_body)
59
- doc = Nokogiri::HTML(html_body)
60
-
61
- # 5. Extract the main title from the live response (using response.body)
62
- live_doc = Nokogiri::HTML(response.body)
63
- page_title = live_doc.at('h1').text.strip
64
-
65
- # Clean the simulated price
66
- parsed_price = doc.at('#price').text.strip.delete('$').to_f
67
-
68
- # Return the parsed and live data
69
- {
70
- "Source (Title)" => page_title,
71
- "Shop A (Simulated Price)" => parsed_price,
72
- "Shop B (Hardcoded Price)" => item_name == 'Coffee Maker' ? 149.0 : 79.0
73
- }
74
- end
75
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "nokogiri"
5
+ require "openssl" # Required for SSL bypass
6
+
7
+ module PricePulse
8
+ class Tracker
9
+ def initialize(items)
10
+ @items = items
11
+ end
12
+
13
+ def compare_prices(item_name)
14
+ target_price = @items[item_name]
15
+ return "Item not found." unless target_price
16
+
17
+ full_prices = get_prices(item_name)
18
+
19
+ # 1. Filter out non-numerical data (like the page title)
20
+ numerical_prices = full_prices.reject { |key, value| key == "Source (Title)" }
21
+
22
+ # 2. Find the best price and shop
23
+ best_price = numerical_prices.values.min
24
+ best_shop = numerical_prices.key(best_price)
25
+
26
+ report = ["--- Tracking: #{item_name} (Target: $#{target_price}) ---"]
27
+
28
+ # List all prices, including the live title
29
+ full_prices.each { |shop, price| report << " - #{shop} price: #{price.is_a?(String) ? price : "$#{price}"}" }
30
+
31
+ if best_price < target_price
32
+ report << " => **DEAL!** Below target price of $#{target_price}"
33
+ else
34
+ report << " => Price is currently $#{best_price}, waiting for a better deal."
35
+ end
36
+ report << "Best Current Price Found: $#{best_price} at #{best_shop}"
37
+ report.join("\n")
38
+ end
39
+
40
+ private
41
+
42
+ def get_prices(item_name)
43
+ # 1. Define the URL dynamically using the item_name
44
+ # The gsub replaces spaces with underscores, a common URL convention.
45
+ wiki_item_name = item_name.gsub(' ', '_')
46
+ url_base = "https://en.wikipedia.org/wiki/#{wiki_item_name}"
47
+ uri = URI.parse(url_base)
48
+
49
+ # 2. Execute the live web request with SSL bypass
50
+ http = Net::HTTP.new(uri.host, uri.port)
51
+ http.use_ssl = true
52
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
53
+ response = http.request_get(uri.request_uri)
54
+
55
+ # 3. Define the simulated HTML body for price parsing
56
+ html_body = "<html><body><div id='price'>$#{item_name == 'Coffee Maker' ? 170.0 : 85.0}</div></body></html>"
57
+
58
+ # 4. Use Nokogiri to parse the simulated HTML
59
+ doc = Nokogiri::HTML(html_body)
60
+ parsed_price = doc.at('#price').text.strip.delete('$').to_f
61
+
62
+ # 5. Extract the main title from the live response (to confirm live fetch worked)
63
+ live_doc = Nokogiri::HTML(response.body)
64
+ page_title = live_doc.at('h1').text.strip
65
+
66
+ # Return the parsed and live data
67
+ {
68
+ "Source (Title)" => page_title,
69
+ "Shop A (Simulated Price)" => parsed_price,
70
+ "Shop B (Hardcoded Price)" => item_name == 'Coffee Maker' ? 149.0 : 79.0
71
+ }
72
+ end
73
+ end
76
74
  end
@@ -1,13 +1,12 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "price_pulse/tracker"
4
-
5
- module PricePulse
6
- VERSION = "0.1.0"
7
-
8
- class Error < StandardError; end
9
-
10
- def self.status
11
- "PricePulse is running version #{VERSION}"
12
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "price_pulse/tracker"
4
+
5
+ module PricePulse
6
+ VERSION = "0.1.0"
7
+ class Error < StandardError; end
8
+
9
+ def self.status
10
+ "PricePulse is running version #{VERSION}"
11
+ end
13
12
  end
data/price_pulse.gemspec CHANGED
@@ -1,24 +1,24 @@
1
- # frozen_string_literal: true
2
-
3
- VERSION = "0.1.0"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "price_pulse"
7
- spec.version = VERSION
8
- spec.authors = ["Your Name"]
9
- spec.email = ["your@email.com"]
10
-
11
- spec.summary = "A Ruby Gem for tracking and mapping prices from various sources."
12
- spec.description = "The PricePulse gem provides a structured way to handle price data collection and analysis."
13
- spec.homepage = "https://rubygems.org/gems/price_pulse"
14
- spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.7.0"
16
-
17
- spec.files = Dir.glob("lib/**/*") + %w(price_pulse.gemspec)
18
- spec.bindir = "exe"
19
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
21
-
22
- # Final dependencies needed for functionality
23
- spec.add_dependency "nokogiri", "~> 1.15"
1
+ # frozen_string_literal: true
2
+
3
+ VERSION = "0.1.1" # Version defined directly here
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "price_pulse"
7
+ spec.version = VERSION
8
+ spec.authors = ["Your Name"]
9
+ spec.email = ["your@email.com"]
10
+
11
+ spec.summary = "A Ruby Gem for tracking and mapping prices from various sources."
12
+ spec.description = "The PricePulse gem provides a structured way to handle price data collection and analysis."
13
+ spec.homepage = "https://github.com/your-username/price_pulse"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.7.0"
16
+
17
+ spec.files = Dir.glob("lib/**/*") + %w(price_pulse.gemspec)
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
20
+
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "nokogiri", "~> 1.15"
24
24
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: price_pulse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Your Name
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-11-14 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: nokogiri
@@ -32,14 +31,13 @@ executables: []
32
31
  extensions: []
33
32
  extra_rdoc_files: []
34
33
  files:
35
- - lib/price_pulse_project/price_pulse.rb
36
- - lib/price_pulse_project/tracker.rb
34
+ - lib/price_pulse.rb
35
+ - lib/price_pulse/tracker.rb
37
36
  - price_pulse.gemspec
38
- homepage: https://rubygems.org/gems/price_pulse
37
+ homepage: https://github.com/your-username/price_pulse
39
38
  licenses:
40
39
  - MIT
41
40
  metadata: {}
42
- post_install_message:
43
41
  rdoc_options: []
44
42
  require_paths:
45
43
  - lib
@@ -54,8 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
52
  - !ruby/object:Gem::Version
55
53
  version: '0'
56
54
  requirements: []
57
- rubygems_version: 3.4.10
58
- signing_key:
55
+ rubygems_version: 3.6.9
59
56
  specification_version: 4
60
57
  summary: A Ruby Gem for tracking and mapping prices from various sources.
61
58
  test_files: []