Class: Html2rss::MCP::Outcome
- Inherits:
-
Data
- Object
- Data
- Html2rss::MCP::Outcome
- Defined in:
- lib/html2rss/mcp/outcome.rb,
lib/html2rss/mcp/outcome.rb,
lib/html2rss/mcp/outcome/playbook.rb
Overview
Typed MCP tool result. Owns next-step policy; guidance copy lives in Playbook.
Defined Under Namespace
Constant Summary collapse
- XOR_ERROR =
Matches ConfigArgument XOR
ArgumentErrormessages. /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?, quality_report: nil) ⇒ Outcome
- .batch_inspect(batch_result) ⇒ Outcome
- .batch_recon(batch_result) ⇒ Outcome
- .batch_scrape(batch_result) ⇒ Outcome
- .capture(yaml:, articles_count:, has_selectors:, channel_title:, requested_strategy:, segment_strategy: nil, selected_strategy: nil, admission_drops: {}, native_feed: nil, suggested_channel_url: nil) ⇒ Outcome
- .from_error(error) ⇒ Outcome
- .inspect(report:) ⇒ Outcome
- .recon(result:) ⇒ Outcome
- .scrape(items:, requested_strategy:, channel_title:, botasaurus_configured:, admission_drops: {}) ⇒ Outcome
- .test(test_result) ⇒ 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.
41 42 43 44 45 46 |
# File 'lib/html2rss/mcp/outcome.rb', line 41 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?, quality_report: nil) ⇒ Outcome
152 153 154 155 156 157 158 |
# File 'lib/html2rss/mcp/outcome.rb', line 152 def apply(rss:, item_count:, empty: item_count.zero?, quality_report: nil) ok = !empty next_step = ok ? NextStep.done : NextStep.inspect payload = { rss:, item_count: } payload[:quality_report] = quality_report if quality_report new(ok:, next_step:, guidance: next_step.guidance, payload:) end |
.batch_inspect(batch_result) ⇒ Outcome
139 |
# File 'lib/html2rss/mcp/outcome.rb', line 139 def batch_inspect(batch_result) = batch(batch_result, NextStep.inspect) |
.batch_recon(batch_result) ⇒ Outcome
144 |
# File 'lib/html2rss/mcp/outcome.rb', line 144 def batch_recon(batch_result) = batch(batch_result, NextStep.recon) |
.batch_scrape(batch_result) ⇒ Outcome
134 |
# File 'lib/html2rss/mcp/outcome.rb', line 134 def batch_scrape(batch_result) = batch(batch_result, NextStep.scrape) |
.capture(yaml:, articles_count:, has_selectors:, channel_title:, requested_strategy:, segment_strategy: nil, selected_strategy: nil, admission_drops: {}, native_feed: nil, suggested_channel_url: nil) ⇒ Outcome
98 99 100 101 102 103 104 105 106 107 |
# 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: {}, native_feed: nil, suggested_channel_url: nil) next_step = capture_next_step(articles_count:, has_selectors:, native_feed:) 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:, native_feed:, suggested_channel_url: )) end |
.from_error(error) ⇒ Outcome
163 164 165 166 167 |
# File 'lib/html2rss/mcp/outcome.rb', line 163 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(report:) ⇒ Outcome
71 72 73 74 75 |
# File 'lib/html2rss/mcp/outcome.rb', line 71 def inspect(report:) next_step = inspect_next_step(report) guidance = Playbook.inspect_guidance(report) new(ok: true, next_step:, guidance:, payload: report.to_wire_h) end |
.recon(result:) ⇒ Outcome
80 81 82 83 84 |
# File 'lib/html2rss/mcp/outcome.rb', line 80 def recon(result:) next_step = recon_next_step(result) guidance = Playbook.recon_guidance(result, next_step) new(ok: true, next_step:, guidance:, payload: result.to_h) end |
.scrape(items:, requested_strategy:, channel_title:, botasaurus_configured:, admission_drops: {}) ⇒ Outcome
62 63 64 65 66 |
# File 'lib/html2rss/mcp/outcome.rb', line 62 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 |
.test(test_result) ⇒ Outcome
121 122 123 124 125 126 127 128 129 |
# File 'lib/html2rss/mcp/outcome.rb', line 121 def test(test_result) next_step = test_next_step(test_result) new( ok: test_result.success, next_step:, guidance: test_guidance(test_result, next_step), payload: test_result.to_h ) end |
Instance Method Details
#to_h ⇒ Hash{Symbol => Object}
Returns envelope for Contract.response.
50 51 52 |
# File 'lib/html2rss/mcp/outcome.rb', line 50 def to_h { ok:, next_step: next_step.name.to_s, guidance:, payload: } end |