Class: Html2rss::MCP::Outcome

Inherits:
Data
  • Object
show all
Defined in:
lib/html2rss/mcp/outcome.rb,
lib/html2rss/mcp/outcome.rb

Overview

Typed MCP tool result. Owns next-step policy and guidance copy so the protocol adapter does not branch on quality heuristics.

Defined Under Namespace

Classes: NextStep

Constant Summary collapse

XOR_ERROR =

Matches ConfigArgument XOR ArgumentError messages.

/exactly one of config or yaml/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ok:, next_step:, guidance:, payload:) ⇒ Outcome

Returns a new instance of Outcome.

Parameters:

  • ok (Boolean)
  • next_step (NextStep)
  • guidance (String)
  • payload (Hash)

Raises:

  • (ArgumentError)


53
54
55
56
57
58
# File 'lib/html2rss/mcp/outcome.rb', line 53

def initialize(ok:, next_step:, guidance:, payload:) # rubocop:disable Naming/MethodParameterName -- +ok+ is the envelope field
  raise ArgumentError, 'next_step must be a NextStep' unless next_step.is_a?(NextStep)
  raise ArgumentError, 'payload must be a Hash' unless payload.is_a?(Hash)

  super(ok: !!ok, next_step:, guidance: guidance.to_s.freeze, payload: payload.dup.freeze)
end

Instance Attribute Details

#guidanceObject (readonly)

Returns the value of attribute guidance

Returns:

  • (Object)

    the current value of guidance



5
6
7
# File 'lib/html2rss/mcp/outcome.rb', line 5

def guidance
  @guidance
end

#next_stepObject (readonly)

Returns the value of attribute next_step

Returns:

  • (Object)

    the current value of next_step



5
6
7
# File 'lib/html2rss/mcp/outcome.rb', line 5

def next_step
  @next_step
end

#okObject (readonly)

Returns the value of attribute ok

Returns:

  • (Object)

    the current value of ok



5
6
7
# File 'lib/html2rss/mcp/outcome.rb', line 5

def ok
  @ok
end

#payloadObject (readonly)

Returns the value of attribute payload

Returns:

  • (Object)

    the current value of payload



5
6
7
# File 'lib/html2rss/mcp/outcome.rb', line 5

def payload
  @payload
end

Class Method Details

.apply(rss:, item_count:, empty: item_count.zero?) ⇒ Outcome

Parameters:

  • rss (String)
  • item_count (Integer)
  • empty (Boolean) (defaults to: item_count.zero?)

    FeedResult#empty? (ship gate); defaults to zero items

Returns:



121
122
123
124
125
# File 'lib/html2rss/mcp/outcome.rb', line 121

def apply(rss:, item_count:, empty: item_count.zero?)
  ok = !empty
  next_step = ok ? NextStep.done : NextStep.inspect_url
  new(ok:, next_step:, guidance: next_step.guidance, payload: { rss:, item_count: })
end

.capture(yaml:, articles_count:, has_selectors:, channel_title:, requested_strategy:, segment_strategy: nil, selected_strategy: nil, admission_drops: {}) ⇒ Outcome

Parameters:

  • yaml (String)
  • articles_count (Integer)
  • has_selectors (Boolean)
  • channel_title (String, nil)
  • requested_strategy (String, Symbol)
  • segment_strategy (Symbol, String, nil) (defaults to: nil)
  • selected_strategy (Symbol, String, nil) (defaults to: nil)
  • admission_drops (Hash) (defaults to: {})

Returns:



98
99
100
101
102
103
104
105
# File 'lib/html2rss/mcp/outcome.rb', line 98

def capture(yaml:, articles_count:, has_selectors:, channel_title:, requested_strategy:, # rubocop:disable Metrics/ParameterLists
            segment_strategy: nil, selected_strategy: nil, admission_drops: {})
  next_step = capture_next_step(articles_count:, has_selectors:)
  new(ok: true, next_step:, guidance: next_step.guidance, payload: capture_payload(
    yaml:, articles_count:, has_selectors:, channel_title:, requested_strategy:,
    segment_strategy:, selected_strategy:, admission_drops:
  ))
end

.from_error(error) ⇒ Outcome

Parameters:

  • error (Exception)

Returns:



130
131
132
133
134
# File 'lib/html2rss/mcp/outcome.rb', line 130

def from_error(error)
  next_step = next_step_for_error(error)
  new(ok: false, next_step:, guidance: next_step.guidance,
      payload: { class: error.class.name, message: error.message })
end

.inspect(payload:) ⇒ Outcome

Parameters:

  • payload (Hash)

    inspect recon Hash

Returns:



83
84
85
86
# File 'lib/html2rss/mcp/outcome.rb', line 83

def inspect(payload:)
  next_step = inspect_next_step(payload)
  new(ok: true, next_step:, guidance: next_step.guidance, payload:)
end

.scrape(items:, requested_strategy:, channel_title:, botasaurus_configured:, admission_drops: {}) ⇒ Outcome

Parameters:

  • items (Array)
  • requested_strategy (String, Symbol)
  • channel_title (String, nil)
  • admission_drops (Hash) (defaults to: {})
  • botasaurus_configured (Boolean)

Returns:



74
75
76
77
78
# File 'lib/html2rss/mcp/outcome.rb', line 74

def scrape(items:, requested_strategy:, channel_title:, botasaurus_configured:, admission_drops: {})
  next_step = scrape_next_step(items.empty?, botasaurus_configured:)
  new(ok: true, next_step:, guidance: next_step.guidance,
      payload: scrape_payload(items:, requested_strategy:, channel_title:, admission_drops:))
end

.validate(errors:) ⇒ Outcome

Parameters:

  • errors (Hash, nil)

    schema errors; nil means success

Returns:



110
111
112
113
114
# File 'lib/html2rss/mcp/outcome.rb', line 110

def validate(errors:)
  ok = errors.nil?
  next_step = ok ? NextStep.apply_config : NextStep.validate_config
  new(ok:, next_step:, guidance: next_step.guidance, payload: ok ? {} : { errors: })
end

Instance Method Details

#to_hHash{Symbol => Object}

Returns envelope for Contract.response.

Returns:



62
63
64
# File 'lib/html2rss/mcp/outcome.rb', line 62

def to_h
  { ok:, next_step: next_step.name.to_s, guidance:, payload: }
end