Class: Html2rss::MCP::Outcome
- Inherits:
-
Data
- Object
- Data
- Html2rss::MCP::Outcome
- 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
-
#guidance ⇒ Object
readonly
Returns the value of attribute guidance.
-
#next_step ⇒ Object
readonly
Returns the value of attribute next_step.
-
#ok ⇒ Object
readonly
Returns the value of attribute ok.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Class Method Summary collapse
- .apply(rss:, item_count:, empty: item_count.zero?) ⇒ Outcome
- .capture(yaml:, articles_count:, has_selectors:, channel_title:, requested_strategy:, segment_strategy: nil, selected_strategy: nil, admission_drops: {}) ⇒ Outcome
- .from_error(error) ⇒ Outcome
- .inspect(payload:) ⇒ Outcome
- .scrape(items:, requested_strategy:, channel_title:, botasaurus_configured:, admission_drops: {}) ⇒ Outcome
- .validate(errors:) ⇒ Outcome
Instance Method Summary collapse
-
#initialize(ok:, next_step:, guidance:, payload:) ⇒ Outcome
constructor
A new instance of Outcome.
-
#to_h ⇒ Hash{Symbol => Object}
Envelope for Contract.response.
Constructor Details
#initialize(ok:, next_step:, guidance:, payload:) ⇒ Outcome
Returns a new instance of Outcome.
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
#guidance ⇒ Object (readonly)
Returns the value of attribute guidance
5 6 7 |
# File 'lib/html2rss/mcp/outcome.rb', line 5 def guidance @guidance end |
#next_step ⇒ Object (readonly)
Returns the value of attribute next_step
5 6 7 |
# File 'lib/html2rss/mcp/outcome.rb', line 5 def next_step @next_step end |
#ok ⇒ Object (readonly)
Returns the value of attribute ok
5 6 7 |
# File 'lib/html2rss/mcp/outcome.rb', line 5 def ok @ok end |
#payload ⇒ Object (readonly)
Returns the value of attribute 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
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
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
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. }) end |
.inspect(payload:) ⇒ Outcome
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
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 |
Instance Method Details
#to_h ⇒ Hash{Symbol => Object}
Returns envelope for Contract.response.
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 |