Class: Html2rss::FeedPipeline::AutoFallback::AttemptState

Inherits:
Object
  • Object
show all
Defined in:
lib/html2rss/feed_pipeline/auto_fallback.rb

Overview

Mutable run state for one auto-fallback chain: attempts plus selected result.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAttemptState

Returns a new instance of AttemptState.



30
31
32
33
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 30

def initialize
  @attempts = []
  @result = nil
end

Instance Attribute Details

#attemptsObject (readonly)

Returns the value of attribute attempts.



28
29
30
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 28

def attempts
  @attempts
end

#resultObject (readonly)

Returns the value of attribute result.



28
29
30
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 28

def result
  @result
end

Instance Method Details

#record_error(strategy:, error:) ⇒ void

This method returns an undefined value.

Parameters:

  • strategy (Symbol)

    strategy that raised

  • error (Exception)

    caught error



41
42
43
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 41

def record_error(strategy:, error:)
  @attempts << { strategy:, items_count: nil, error_class: error.class.name }
end

#record_items(strategy:, items_count:) ⇒ void

This method returns an undefined value.

Parameters:

  • strategy (Symbol)

    strategy that returned a response

  • items_count (Integer)

    extracted article count



48
49
50
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 48

def record_items(strategy:, items_count:)
  @attempts << { strategy:, items_count:, error_class: nil }
end

#succeed!(response:, articles:) ⇒ void

This method returns an undefined value.

Parameters:



55
56
57
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 55

def succeed!(response:, articles:)
  @result = { response:, articles: }
end

#succeeded?Boolean

Returns true when a strategy already yielded items.

Returns:

  • (Boolean)

    true when a strategy already yielded items



36
# File 'lib/html2rss/feed_pipeline/auto_fallback.rb', line 36

def succeeded? = !result.nil?