Class: LigaMagicScraper::Alerts::FileAlert
- Includes:
- Loggable
- Defined in:
- lib/ligamagic_scraper/alerts/file_alert.rb
Constant Summary collapse
- ALERTS_BASE_DIR =
'alerts_json'
Instance Attribute Summary
Attributes included from Loggable
Instance Method Summary collapse
-
#initialize ⇒ FileAlert
constructor
A new instance of FileAlert.
- #notify(changes) ⇒ Object
Methods included from Loggable
#clear_logs, #formatted_logs, #initialize_logs, #log, #log_debug, #log_error, #log_info, #log_warning
Constructor Details
#initialize ⇒ FileAlert
Returns a new instance of FileAlert.
12 13 14 15 |
# File 'lib/ligamagic_scraper/alerts/file_alert.rb', line 12 def initialize super initialize_logs end |
Instance Method Details
#notify(changes) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ligamagic_scraper/alerts/file_alert.rb', line 17 def notify(changes) log_info("📁 FileAlert: Saving changes to JSON file...") subdir = if changes[:search_type] == 'store' search_identifier = sanitize_filename(changes[:search_term] || 'unknown') File.join(ALERTS_BASE_DIR, 'stores', search_identifier) else File.join(ALERTS_BASE_DIR, 'global') end FileUtils.mkdir_p(subdir) unless Dir.exist?(subdir) filename = generate_alert_filename(changes) filepath = File.join(subdir, filename) File.write(filepath, JSON.pretty_generate(changes)) log_info(" ✅ Changes saved to: #{filepath}") log_info(" 📊 Summary:") log_info(" 🆕 New products: #{changes[:new_products].count}") log_info(" ❌ Removed products: #{changes[:removed_products].count}") log_info(" 💰 Price changes: #{changes[:price_changes].count}") log_info(" 📊 Quantity changes: #{changes[:quantity_changes].count}") if changes[:quantity_changes] log_info(" 📦 Availability changes: #{changes[:availability_changes].count}") end |