Class: Prosereflect::Transform::DeleteStep
- Defined in:
- lib/prosereflect/transform/insert_step.rb
Overview
Delete content in a range
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Class Method Summary collapse
Instance Method Summary collapse
- #apply(doc) ⇒ Object
- #get_map ⇒ Object
-
#initialize(from, to) ⇒ DeleteStep
constructor
A new instance of DeleteStep.
- #invert(doc) ⇒ Object
- #step_type ⇒ Object
- #to_json(*_args) ⇒ Object
Methods inherited from Step
Constructor Details
#initialize(from, to) ⇒ DeleteStep
Returns a new instance of DeleteStep.
62 63 64 65 66 |
# File 'lib/prosereflect/transform/insert_step.rb', line 62 def initialize(from, to) super() @from = from @to = to end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
60 61 62 |
# File 'lib/prosereflect/transform/insert_step.rb', line 60 def from @from end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
60 61 62 |
# File 'lib/prosereflect/transform/insert_step.rb', line 60 def to @to end |
Class Method Details
.from_json(_schema, json) ⇒ Object
102 103 104 |
# File 'lib/prosereflect/transform/insert_step.rb', line 102 def self.from_json(_schema, json) new(json["from"], json["to"]) end |
Instance Method Details
#apply(doc) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/prosereflect/transform/insert_step.rb', line 68 def apply(doc) return Result.fail("Invalid positions") if @from > @to return Result.fail("from < 0") if @from.negative? return Result.fail("to > doc size") if @to > doc.node_size begin replace_step = ReplaceStep.new(@from, @to, Slice.empty) replace_step.apply(doc) rescue StandardError => e Result.fail(e.) end end |
#get_map ⇒ Object
81 82 83 |
# File 'lib/prosereflect/transform/insert_step.rb', line 81 def get_map StepMap.delete(@from, @to) end |
#invert(doc) ⇒ Object
85 86 87 88 89 |
# File 'lib/prosereflect/transform/insert_step.rb', line 85 def invert(doc) # Find what was deleted deleted = content_between(doc, @from, @to) InsertStep.new(@from, deleted) end |
#step_type ⇒ Object
91 92 93 |
# File 'lib/prosereflect/transform/insert_step.rb', line 91 def step_type "delete" end |
#to_json(*_args) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/prosereflect/transform/insert_step.rb', line 95 def to_json(*_args) json = super json["from"] = @from json["to"] = @to json end |