Class: Prosereflect::Transform::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/prosereflect/transform/step.rb

Overview

Base class for all document transformations. A step represents an atomic document change.

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_json(_schema, _json) ⇒ Object

Create a step from JSON

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


13
14
15
# File 'lib/prosereflect/transform/step.rb', line 13

def apply(_doc)
  raise NotImplementedError, "#{self.class} must implement #apply"
end

#get_mapObject

Get the step map for position tracking

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


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

#posObject

Position where this step applies



54
55
56
# File 'lib/prosereflect/transform/step.rb', line 54

def pos
  0
end

#step_typeObject

The type name of this step

Raises:

  • (NotImplementedError)


49
50
51
# File 'lib/prosereflect/transform/step.rb', line 49

def step_type
  raise NotImplementedError, "#{self.class} must implement #step_type"
end

#toObject

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