price_pulse 0.1.5 → 0.1.6

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: 0ce5d1550b80e37178cabe2fc3abd27fe9b9d26fcc16d34f7231c2ff826c2eb0
4
- data.tar.gz: e1eb895c0f15ad6251aad2c22367498f312d94f5370c23af28347060bf42fe2a
3
+ metadata.gz: 1517864f69948790dbcbe0d17a6fc3f732189ea2683aac9035cbc325b22fb8f4
4
+ data.tar.gz: ebed52d7668fa86df202b889599644b6a4614fea823ac682eca59c9cb9b6a1b8
5
5
  SHA512:
6
- metadata.gz: 112a2e9695d8456d9fc5b54dfaf2004e9ddde4ed4a8b21cc0d47357bfcf73fc84fab95f023e790365ac58fcf91e473b9549b7b792df643949523a42bcfffa9c6
7
- data.tar.gz: 37a60c40a3f1d67fc76e39373713cc5764b510d92f52d55586cd78dfbb67ea593ec7a31ed1f30327476e2a709a63a5dff949ae4aa116ca8d3ddb904760a0b486
6
+ metadata.gz: 858a199baa32831013a1ddf5613cdf80b9fd8f6e2fa79f0771b8357503dafbd32b2ff8c5fdbed78361daaff81727af328ab3b79d80dfd68d552f4283ea0c3d24
7
+ data.tar.gz: 6593955a4907b37e7d0cde73eda891149830ac466e1645d95185d4c76def4afe3fc3ca4b46b0249160a9a9c3a9da8c926379dd6a613a69b5bec0c908001c68cc
@@ -2,17 +2,33 @@
2
2
 
3
3
  module PricePulse
4
4
  module Configuration
5
- # The official version of the Gem
6
- VERSION = "0.1.5"
7
-
8
- # Base URL used for testing, validation, and general lookups
5
+ # --- STATIC (Read-Only) Settings ---
6
+ VERSION = "0.1.6"
9
7
  BASE_VALIDATION_URL = "https://en.wikipedia.org/wiki/"
10
-
8
+
11
9
  # List of all available parser classes
12
10
  PARSERS = [
13
11
  :AmazonParser,
14
12
  :BestBuyParser,
15
13
  :WalmartParser
16
14
  ].freeze
15
+
16
+ # --- DYNAMIC (Runtime) Settings ---
17
+ # @config holds user-defined overrides for selectors, API keys, etc.
18
+ @config = {}
19
+
20
+ # Default selector the Amazon parser will use if the main one breaks
21
+ @config[:amazon_price_selector] = 'span.a-price-whole'
22
+
23
+ # Reader method for accessing the configuration hash
24
+ def self.config
25
+ @config
26
+ end
27
+
28
+ # Method to allow users to set configuration variables after the Gem loads
29
+ # Example usage: PricePulse::Configuration.configure { |c| c[:amazon_price_selector] = 'new-tag' }
30
+ def self.configure
31
+ yield @config if block_given?
32
+ end
17
33
  end
18
34
  end
@@ -51,22 +51,21 @@ module PricePulse
51
51
  def get_prices(item_name)
52
52
  results = {}
53
53
 
54
- # 1. Fetch Price from Amazon (Simulated)
55
- amazon_url = PricePulse::AmazonParser.get_url(item_name)
56
- simulated_amazon_html = "<html><body>Amazon Listing for #{item_name}</body></html>"
57
- results["Amazon (Parsed)"] = PricePulse::AmazonParser.get_price(simulated_amazon_html)
58
-
59
- # 2. Fetch Price from Best Buy (Simulated)
60
- bestbuy_url = PricePulse::BestBuyParser.get_url(item_name)
61
- simulated_bestbuy_html = "<html><body>Best Buy Listing for #{item_name}</body></html>"
62
- results["Best Buy (Parsed)"] = PricePulse::BestBuyParser.get_price(simulated_bestbuy_html)
54
+ # --- DYNAMICALLY CALL PARSERS ---
55
+ PricePulse::Configuration::PARSERS.each do |parser_name|
56
+ parser = PricePulse.const_get(parser_name) # Convert symbol to class (e.g., :AmazonParser -> PricePulse::AmazonParser)
63
57
 
64
- # 3. Fetch Price from Walmart (Simulated)
65
- walmart_url = PricePulse::WalmartParser.get_url(item_name)
66
- simulated_walmart_html = "<html><body>Walmart Listing for #{item_name}</body></html>"
67
- results["Walmart (Parsed)"] = PricePulse::WalmartParser.get_price(simulated_walmart_html)
58
+ # Simulate fetching site content for parsing
59
+ simulated_html = "<html><body>#{parser_name} Listing for #{item_name}</body></html>"
60
+
61
+ # Get simulated price from the specialist parser
62
+ simulated_price = parser.get_price(simulated_html)
63
+
64
+ results["#{parser_name.to_s.gsub('Parser', '')} (Parsed)"] = simulated_price
65
+ end
66
+ # --- END DYNAMIC CALL ---
68
67
 
69
- # 4. Wikipedia (Live fetch for title validation with Error Handling)
68
+ # Wikipedia (Live fetch for title validation with Error Handling)
70
69
  wiki_item_name = item_name.gsub(' ', '_')
71
70
  url_base = "https://en.wikipedia.org/wiki/#{wiki_item_name}"
72
71
  uri = URI.parse(url_base)
@@ -86,7 +85,7 @@ module PricePulse
86
85
  results["Source (Title)"] = "Error: Network connection failed. (#{e.class})"
87
86
  end
88
87
 
89
- # 5. Add a static price for Shop B to ensure we find a deal in the test
88
+ # Add a static price for Shop B to ensure we find a deal in the test
90
89
  results["Shop B (Hardcoded Price)"] = item_name == 'Coffee Maker' ? 149.0 : 79.0
91
90
 
92
91
  return results
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: price_pulse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Your Name