Class: Html2rss::Test::Result

Inherits:
Data
  • Object
show all
Defined in:
lib/html2rss/test.rb

Overview

Immutable outcome of a configuration test. Success carries rss XML from the first live extraction; failures carry a typed FailureKind.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(success:, item_count:, sample_items:, channel_title:, channel_url:, strategy_used:, duration_seconds:, validation_errors:, error_message:, failure_kind:, rss:, quality_report: nil, enhance_compare: nil) ⇒ Result

Returns a new instance of Result.

Parameters:

  • success (Boolean)
  • item_count (Integer)
  • sample_items (Array<Hash>)
  • channel_title (String, nil)
  • channel_url (String, nil)
  • strategy_used (Symbol, nil)
  • duration_seconds (Float)
  • validation_errors (Hash, nil)
  • error_message (String, nil)
  • failure_kind (FailureKind, nil)
  • rss (String, nil)
  • quality_report (QualityReport, nil) (defaults to: nil)
  • enhance_compare (Hash, nil) (defaults to: nil)


122
123
124
125
126
# File 'lib/html2rss/test.rb', line 122

def initialize(success:, item_count:, sample_items:, channel_title:, channel_url:, # rubocop:disable Metrics/ParameterLists
               strategy_used:, duration_seconds:, validation_errors:, error_message:,
               failure_kind:, rss:, quality_report: nil, enhance_compare: nil)
  super
end

Instance Attribute Details

#channel_titleObject (readonly)

Returns the value of attribute channel_title

Returns:

  • (Object)

    the current value of channel_title



93
94
95
# File 'lib/html2rss/test.rb', line 93

def channel_title
  @channel_title
end

#channel_urlObject (readonly)

Returns the value of attribute channel_url

Returns:

  • (Object)

    the current value of channel_url



93
94
95
# File 'lib/html2rss/test.rb', line 93

def channel_url
  @channel_url
end

#duration_secondsObject (readonly)

Returns the value of attribute duration_seconds

Returns:

  • (Object)

    the current value of duration_seconds



93
94
95
# File 'lib/html2rss/test.rb', line 93

def duration_seconds
  @duration_seconds
end

#enhance_compareObject (readonly)

Returns the value of attribute enhance_compare

Returns:

  • (Object)

    the current value of enhance_compare



93
94
95
# File 'lib/html2rss/test.rb', line 93

def enhance_compare
  @enhance_compare
end

#error_messageObject (readonly)

Returns the value of attribute error_message

Returns:

  • (Object)

    the current value of error_message



93
94
95
# File 'lib/html2rss/test.rb', line 93

def error_message
  @error_message
end

#failure_kindObject (readonly)

Returns the value of attribute failure_kind

Returns:

  • (Object)

    the current value of failure_kind



93
94
95
# File 'lib/html2rss/test.rb', line 93

def failure_kind
  @failure_kind
end

#item_countObject (readonly)

Returns the value of attribute item_count

Returns:

  • (Object)

    the current value of item_count



93
94
95
# File 'lib/html2rss/test.rb', line 93

def item_count
  @item_count
end

#quality_reportObject (readonly)

Returns the value of attribute quality_report

Returns:

  • (Object)

    the current value of quality_report



93
94
95
# File 'lib/html2rss/test.rb', line 93

def quality_report
  @quality_report
end

#rssObject (readonly)

Returns the value of attribute rss

Returns:

  • (Object)

    the current value of rss



93
94
95
# File 'lib/html2rss/test.rb', line 93

def rss
  @rss
end

#sample_itemsObject (readonly)

Returns the value of attribute sample_items

Returns:

  • (Object)

    the current value of sample_items



93
94
95
# File 'lib/html2rss/test.rb', line 93

def sample_items
  @sample_items
end

#strategy_usedObject (readonly)

Returns the value of attribute strategy_used

Returns:

  • (Object)

    the current value of strategy_used



93
94
95
# File 'lib/html2rss/test.rb', line 93

def strategy_used
  @strategy_used
end

#successObject (readonly)

Returns the value of attribute success

Returns:

  • (Object)

    the current value of success



93
94
95
# File 'lib/html2rss/test.rb', line 93

def success
  @success
end

#validation_errorsObject (readonly)

Returns the value of attribute validation_errors

Returns:

  • (Object)

    the current value of validation_errors



93
94
95
# File 'lib/html2rss/test.rb', line 93

def validation_errors
  @validation_errors
end

Instance Method Details

#empty_feed?Boolean

Returns whether the test extracted zero items.

Returns:

  • (Boolean)

    whether the test extracted zero items



136
137
138
# File 'lib/html2rss/test.rb', line 136

def empty_feed?
  item_count.zero?
end

#to_hHash{Symbol => Object}

Returns hash representation.

Returns:

  • (Hash{Symbol => Object})

    hash representation



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/html2rss/test.rb', line 142

def to_h # rubocop:disable Metrics/MethodLength
  {
    success:,
    item_count:,
    sample_items:,
    channel_title:,
    channel_url:,
    strategy_used:,
    duration_seconds:,
    validation_errors:,
    error_message:,
    failure_kind: failure_kind&.to_sym,
    rss:,
    quality_report: quality_report&.to_h,
    enhance_compare:
  }.compact
end

#valid_schema?Boolean

Returns whether the schema validation succeeded.

Returns:

  • (Boolean)

    whether the schema validation succeeded



130
131
132
# File 'lib/html2rss/test.rb', line 130

def valid_schema?
  validation_errors.nil? || validation_errors.empty?
end