Class: Olyx::Guardrails::PolicyComponents::UnmatchedSegmentBuilder
- Inherits:
-
Object
- Object
- Olyx::Guardrails::PolicyComponents::UnmatchedSegmentBuilder
- Defined in:
- lib/olyx/guardrails/policy/unmatched_segment_builder.rb
Overview
Accumulates transformed gaps and fixed policy replacements in source order.
Instance Method Summary collapse
- #append(span) ⇒ Object
- #finish ⇒ Object
-
#initialize(source, transform) ⇒ UnmatchedSegmentBuilder
constructor
A new instance of UnmatchedSegmentBuilder.
Constructor Details
#initialize(source, transform) ⇒ UnmatchedSegmentBuilder
Returns a new instance of UnmatchedSegmentBuilder.
8 9 10 11 12 13 |
# File 'lib/olyx/guardrails/policy/unmatched_segment_builder.rb', line 8 def initialize(source, transform) @source = source @transform = transform @cursor = 0 @parts = [] end |
Instance Method Details
#append(span) ⇒ Object
15 16 17 18 19 |
# File 'lib/olyx/guardrails/policy/unmatched_segment_builder.rb', line 15 def append(span) @parts << @transform.call(@source[@cursor...span[:start]]) @parts << span[:replacement] @cursor = span[:end] end |
#finish ⇒ Object
21 22 23 24 |
# File 'lib/olyx/guardrails/policy/unmatched_segment_builder.rb', line 21 def finish @parts << @transform.call(@source[@cursor..]) @parts.join end |