Class: Prosereflect::Transform::AddMarkStep
Overview
Add a mark to 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
Class Method Details
.from_json(_schema, json) ⇒ Object
62
63
64
65
|
# File 'lib/prosereflect/transform/mark_step.rb', line 62
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
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/prosereflect/transform/mark_step.rb', line 26
def apply(doc)
return Result.fail("Invalid positions") if @from > @to || @from.negative?
begin
new_doc = add_mark_to_range(doc)
Result.ok(new_doc)
rescue StandardError => e
Result.fail(e.message)
end
end
|
#invert(_doc) ⇒ Object
37
38
39
|
# File 'lib/prosereflect/transform/mark_step.rb', line 37
def invert(_doc)
RemoveMarkStep.new(@from, @to, @mark)
end
|
#merge(other) ⇒ Object
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/prosereflect/transform/mark_step.rb', line 41
def merge(other)
return nil unless other.is_a?(AddMarkStep)
return nil unless other.mark == @mark
if @to == other.from
AddMarkStep.new(@from, other.to, @mark)
elsif @from == other.to
AddMarkStep.new(other.from, @to, @mark)
end
end
|
#step_type ⇒ Object
52
53
54
|
# File 'lib/prosereflect/transform/mark_step.rb', line 52
def step_type
"addMark"
end
|
#to_json(*_args) ⇒ Object
56
57
58
59
60
|
# File 'lib/prosereflect/transform/mark_step.rb', line 56
def to_json(*_args)
json = super
json["mark"] = @mark.to_h
json
end
|