Class: Html2rss::Status
- Inherits:
-
Data
- Object
- Data
- Html2rss::Status
- Defined in:
- lib/html2rss/status.rb
Overview
Shared RSS generator / JSON Feed user_comment formatter string.
Exposed publicly via FeedResult#status. Safe to log without reading articles. Stable telemetry payload for cross-repo consumers (e.g. html2rss-web observability). Tallies and counters are validated and frozen at construction (including Marshal load).
Instance Attribute Summary collapse
-
#attempt_count ⇒ Object
readonly
Returns the value of attribute attempt_count.
-
#dedup_dropped ⇒ Object
readonly
Returns the value of attribute dedup_dropped.
-
#scraper_tallies ⇒ Object
readonly
Returns the value of attribute scraper_tallies.
-
#selected_strategy ⇒ Object
readonly
Returns the value of attribute selected_strategy.
-
#strategy_attempts ⇒ Object
readonly
Returns the value of attribute strategy_attempts.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.build(articles:, dedup_dropped: 0, selected_strategy: nil, attempt_count: 0, strategy_attempts: []) ⇒ Html2rss::Status
Builds status from extracted articles and scrape telemetry.
-
.scraper_name(klass) ⇒ String
Short scraper label for tallies / generator text.
Instance Method Summary collapse
-
#initialize(version:, scraper_tallies:, dedup_dropped:, selected_strategy: nil, attempt_count: 0, strategy_attempts: []) ⇒ Status
constructor
rubocop:disable Metrics/ParameterLists, Metrics/MethodLength -- Status Data.define members.
-
#to_generator_comment ⇒ String
Formats the RSS
generatorstring and JSON Feeduser_comment. -
#to_h ⇒ Hash{Symbol => Object}
Observability hash for web (+scraper_status+).
Constructor Details
#initialize(version:, scraper_tallies:, dedup_dropped:, selected_strategy: nil, attempt_count: 0, strategy_attempts: []) ⇒ Status
rubocop:disable Metrics/ParameterLists, Metrics/MethodLength -- Status Data.define members
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/html2rss/status.rb', line 51 def initialize( version:, scraper_tallies:, dedup_dropped:, selected_strategy: nil, attempt_count: 0, strategy_attempts: [] ) dedup = Integer(dedup_dropped) attempts = Integer(attempt_count) validate_counters!(dedup:, attempts:, selected_strategy:) super( version: version.to_s.dup.freeze, scraper_tallies: freeze_tallies(scraper_tallies), dedup_dropped: dedup, selected_strategy:, attempt_count: attempts, strategy_attempts: freeze_attempts(strategy_attempts) ) end |
Instance Attribute Details
#attempt_count ⇒ Object (readonly)
Returns the value of attribute attempt_count
10 11 12 |
# File 'lib/html2rss/status.rb', line 10 def attempt_count @attempt_count end |
#dedup_dropped ⇒ Object (readonly)
Returns the value of attribute dedup_dropped
10 11 12 |
# File 'lib/html2rss/status.rb', line 10 def dedup_dropped @dedup_dropped end |
#scraper_tallies ⇒ Object (readonly)
Returns the value of attribute scraper_tallies
10 11 12 |
# File 'lib/html2rss/status.rb', line 10 def scraper_tallies @scraper_tallies end |
#selected_strategy ⇒ Object (readonly)
Returns the value of attribute selected_strategy
10 11 12 |
# File 'lib/html2rss/status.rb', line 10 def selected_strategy @selected_strategy end |
#strategy_attempts ⇒ Object (readonly)
Returns the value of attribute strategy_attempts
10 11 12 |
# File 'lib/html2rss/status.rb', line 10 def strategy_attempts @strategy_attempts end |
#version ⇒ Object (readonly)
Returns the value of attribute version
10 11 12 |
# File 'lib/html2rss/status.rb', line 10 def version @version end |
Class Method Details
.build(articles:, dedup_dropped: 0, selected_strategy: nil, attempt_count: 0, strategy_attempts: []) ⇒ Html2rss::Status
Builds status from extracted articles and scrape telemetry.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/html2rss/status.rb', line 23 def build(articles:, dedup_dropped: 0, selected_strategy: nil, attempt_count: 0, strategy_attempts: []) tallies = articles.filter_map(&:scraper).tally.transform_keys { |klass| scraper_name(klass) } new( version: Html2rss::VERSION, scraper_tallies: tallies, dedup_dropped:, selected_strategy:, attempt_count:, strategy_attempts: ) end |
.scraper_name(klass) ⇒ String
Returns short scraper label for tallies / generator text.
38 39 40 |
# File 'lib/html2rss/status.rb', line 38 def scraper_name(klass) klass.to_s.gsub(/(?:Html2rss|Scraper)::/, '') end |
Instance Method Details
#to_generator_comment ⇒ String
Formats the RSS generator string and JSON Feed user_comment.
Scraper-focused only — auto strategy summary stays on #to_h, not this string.
Omits the (scrapers: …) clause when tallies are empty.
94 95 96 97 98 99 |
# File 'lib/html2rss/status.rb', line 94 def to_generator_comment return "html2rss V. #{version}" if scraper_tallies.empty? counts = scraper_tallies.map { |name, count| "#{name} (#{count})" } "html2rss V. #{version} (scrapers: #{counts.join(', ')})" end |
#to_h ⇒ Hash{Symbol => Object}
Observability hash for web (+scraper_status+). Omits empty/absent optional keys:
:scraper_tallies when empty, :selected_strategy when nil, :attempt_count when zero,
:strategy_attempts when empty.
Data members remain available via readers even when omitted here.
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/html2rss/status.rb', line 77 def to_h { version:, dedup_dropped:, **(scraper_tallies.any? ? { scraper_tallies: } : {}), **(selected_strategy.nil? ? {} : { selected_strategy: }), **(attempt_count.positive? ? { attempt_count: } : {}), **(strategy_attempts.any? ? { strategy_attempts: } : {}) } end |