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 +4 -4
- data/lib/price_pulse/configuration.rb +21 -5
- data/lib/price_pulse/tracker.rb +14 -15
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1517864f69948790dbcbe0d17a6fc3f732189ea2683aac9035cbc325b22fb8f4
|
|
4
|
+
data.tar.gz: ebed52d7668fa86df202b889599644b6a4614fea823ac682eca59c9cb9b6a1b8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 858a199baa32831013a1ddf5613cdf80b9fd8f6e2fa79f0771b8357503dafbd32b2ff8c5fdbed78361daaff81727af328ab3b79d80dfd68d552f4283ea0c3d24
|
|
7
|
+
data.tar.gz: 6593955a4907b37e7d0cde73eda891149830ac466e1645d95185d4c76def4afe3fc3ca4b46b0249160a9a9c3a9da8c926379dd6a613a69b5bec0c908001c68cc
|
|
@@ -2,17 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
module PricePulse
|
|
4
4
|
module Configuration
|
|
5
|
-
#
|
|
6
|
-
VERSION = "0.1.
|
|
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
|
data/lib/price_pulse/tracker.rb
CHANGED
|
@@ -51,22 +51,21 @@ module PricePulse
|
|
|
51
51
|
def get_prices(item_name)
|
|
52
52
|
results = {}
|
|
53
53
|
|
|
54
|
-
#
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|