Class: Prosereflect::Transform::Step
- Inherits:
-
Object
- Object
- Prosereflect::Transform::Step
- Defined in:
- lib/prosereflect/transform/step.rb
Overview
Base class for all document transformations. A step represents an atomic document change.
Direct Known Subclasses
AddNodeMarkStep, AttrStep, DeleteStep, DocAttrStep, InsertStep, MarkStep, RemoveNodeMarkStep, ReplaceAroundStep, ReplaceStep
Defined Under Namespace
Classes: Result
Class Method Summary collapse
-
.from_json(_schema, _json) ⇒ Object
Create a step from JSON.
Instance Method Summary collapse
-
#apply(_doc) ⇒ Object
Apply this step to a document Returns a Result with the new document or an error.
-
#get_map ⇒ Object
Get the step map for position tracking.
-
#invert(_doc) ⇒ Object
Return an inverted step that undoes this one Takes the document as input to compute the inverse.
-
#merge(_other) ⇒ Object
Merge this step with another if possible Returns a new step or nil if not mergeable.
-
#pos ⇒ Object
Position where this step applies.
-
#step_type ⇒ Object
The type name of this step.
-
#to ⇒ Object
End position (for range steps).
-
#to_json(*_args) ⇒ Object
Get a JSON representation.
Class Method Details
.from_json(_schema, _json) ⇒ Object
Create a step from JSON
44 45 46 |
# File 'lib/prosereflect/transform/step.rb', line 44 def self.from_json(_schema, _json) raise NotImplementedError, "#{self.class} must implement #from_json" end |
Instance Method Details
#apply(_doc) ⇒ Object
Apply this step to a document Returns a Result with the new document or an error
13 14 15 |
# File 'lib/prosereflect/transform/step.rb', line 13 def apply(_doc) raise NotImplementedError, "#{self.class} must implement #apply" end |
#get_map ⇒ Object
Get the step map for position tracking
18 19 20 |
# File 'lib/prosereflect/transform/step.rb', line 18 def get_map raise NotImplementedError, "#{self.class} must implement #get_map" end |
#invert(_doc) ⇒ Object
Return an inverted step that undoes this one Takes the document as input to compute the inverse
30 31 32 |
# File 'lib/prosereflect/transform/step.rb', line 30 def invert(_doc) raise NotImplementedError, "#{self.class} must implement #invert" end |
#merge(_other) ⇒ Object
Merge this step with another if possible Returns a new step or nil if not mergeable
24 25 26 |
# File 'lib/prosereflect/transform/step.rb', line 24 def merge(_other) nil end |
#pos ⇒ Object
Position where this step applies
54 55 56 |
# File 'lib/prosereflect/transform/step.rb', line 54 def pos 0 end |
#step_type ⇒ Object
The type name of this step
49 50 51 |
# File 'lib/prosereflect/transform/step.rb', line 49 def step_type raise NotImplementedError, "#{self.class} must implement #step_type" end |
#to ⇒ Object
End position (for range steps)
59 60 61 |
# File 'lib/prosereflect/transform/step.rb', line 59 def to pos end |
#to_json(*_args) ⇒ Object
Get a JSON representation
35 36 37 38 39 40 41 |
# File 'lib/prosereflect/transform/step.rb', line 35 def to_json(*_args) { "stepType" => step_type, "pos" => pos, "to" => to, }.compact end |