Class: Prosereflect::Transform::AttrStep
- Defined in:
- lib/prosereflect/transform/attr_step.rb
Overview
Set or remove attributes on a node at a position
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
Class Method Summary collapse
Instance Method Summary collapse
- #apply(doc) ⇒ Object
- #get_map ⇒ Object
-
#initialize(pos, attrs) ⇒ AttrStep
constructor
A new instance of AttrStep.
- #invert(doc) ⇒ Object
- #step_type ⇒ Object
- #to_json(*_args) ⇒ Object
Methods inherited from Step
Constructor Details
#initialize(pos, attrs) ⇒ AttrStep
Returns a new instance of AttrStep.
12 13 14 15 16 |
# File 'lib/prosereflect/transform/attr_step.rb', line 12 def initialize(pos, attrs) super() @pos = pos @attrs = attrs end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
10 11 12 |
# File 'lib/prosereflect/transform/attr_step.rb', line 10 def attrs @attrs end |
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
10 11 12 |
# File 'lib/prosereflect/transform/attr_step.rb', line 10 def pos @pos end |
Class Method Details
.from_json(_schema, json) ⇒ Object
50 51 52 |
# File 'lib/prosereflect/transform/attr_step.rb', line 50 def self.from_json(_schema, json) new(json["pos"], json["attrs"]) end |
Instance Method Details
#apply(doc) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/prosereflect/transform/attr_step.rb', line 18 def apply(doc) return Result.fail("Invalid position") if @pos.negative? || @pos > doc.node_size begin new_doc = set_node_attrs(doc) Result.ok(new_doc) rescue StandardError => e Result.fail(e.) end end |
#get_map ⇒ Object
29 30 31 |
# File 'lib/prosereflect/transform/attr_step.rb', line 29 def get_map StepMap.new end |
#invert(doc) ⇒ Object
33 34 35 36 37 |
# File 'lib/prosereflect/transform/attr_step.rb', line 33 def invert(doc) # Find what attrs were changed and revert them old_attrs = get_old_attrs(doc) AttrStep.new(@pos, old_attrs) end |
#step_type ⇒ Object
39 40 41 |
# File 'lib/prosereflect/transform/attr_step.rb', line 39 def step_type "setAttr" end |
#to_json(*_args) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/prosereflect/transform/attr_step.rb', line 43 def to_json(*_args) json = super json["pos"] = @pos json["attrs"] = @attrs json end |