Class: Prosereflect::Transform::RemoveMarkStep

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

Overview

Remove a mark from all content in a range

Instance Attribute Summary

Attributes inherited from MarkStep

#from, #mark, #to

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MarkStep

#get_map, #initialize

Methods inherited from Step

#get_map, #pos, #to

Constructor Details

This class inherits a constructor from Prosereflect::Transform::MarkStep

Class Method Details

.from_json(_schema, json) ⇒ Object



139
140
141
142
# File 'lib/prosereflect/transform/mark_step.rb', line 139

def self.from_json(_schema, json)
  mark = Prosereflect::Mark.from_h(json["mark"])
  new(json["from"], json["to"], mark)
end

Instance Method Details

#apply(doc) ⇒ Object



103
104
105
106
107
108
109
110
111
112
# File 'lib/prosereflect/transform/mark_step.rb', line 103

def apply(doc)
  return Result.fail("Invalid positions") if @from > @to || @from.negative?

  begin
    new_doc = remove_mark_from_range(doc)
    Result.ok(new_doc)
  rescue StandardError => e
    Result.fail(e.message)
  end
end

#invert(_doc) ⇒ Object



114
115
116
# File 'lib/prosereflect/transform/mark_step.rb', line 114

def invert(_doc)
  AddMarkStep.new(@from, @to, @mark)
end

#merge(other) ⇒ Object



118
119
120
121
122
123
124
125
126
127
# File 'lib/prosereflect/transform/mark_step.rb', line 118

def merge(other)
  return nil unless other.is_a?(RemoveMarkStep)
  return nil unless other.mark == @mark

  if @to == other.from
    RemoveMarkStep.new(@from, other.to, @mark)
  elsif @from == other.to
    RemoveMarkStep.new(other.from, @to, @mark)
  end
end

#step_typeObject



129
130
131
# File 'lib/prosereflect/transform/mark_step.rb', line 129

def step_type
  "removeMark"
end

#to_json(*_args) ⇒ Object



133
134
135
136
137
# File 'lib/prosereflect/transform/mark_step.rb', line 133

def to_json(*_args)
  json = super
  json["mark"] = @mark.to_h
  json
end