price_pulse 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4794648ef8458ceddf145a60327ed6932756bbff445d53f36d8755312aa5a90d
4
+ data.tar.gz: ce947c61ec17efc60f61d66afb434804344cc519f1ec49001a5ab994ba864e36
5
+ SHA512:
6
+ metadata.gz: 92f7565f059ad0c63e645d3171b8d6ae0a7865e65790925de7e793b2048283cd8cd2e5f2333f40c6e15054473ffaf0604c840b08fc131bc5efa960d53489e117
7
+ data.tar.gz: d8ad72b348c44b84afbc3d9564e133efbd77f53d453f933c7c9fdbd9466e1e438bac405e092c6c9dde970812bd47db95223da1936acb028a74d5762017671d57
@@ -0,0 +1,13 @@
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
13
+ end
@@ -0,0 +1,76 @@
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
76
+ end
@@ -0,0 +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"
24
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: price_pulse
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Your Name
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-11-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ description: The PricePulse gem provides a structured way to handle price data collection
28
+ and analysis.
29
+ email:
30
+ - your@email.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - lib/price_pulse_project/price_pulse.rb
36
+ - lib/price_pulse_project/tracker.rb
37
+ - price_pulse.gemspec
38
+ homepage: https://rubygems.org/gems/price_pulse
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.7.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.4.10
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: A Ruby Gem for tracking and mapping prices from various sources.
61
+ test_files: []