Class: Canon::TreeDiff::Operations::Operation
- Inherits:
-
Object
- Object
- Canon::TreeDiff::Operations::Operation
- Defined in:
- lib/canon/tree_diff/operations/operation.rb
Overview
Base class for all tree diff operations
Represents a high-level semantic operation detected from tree matching. Each operation has a type, affected nodes, and metadata.
Constant Summary collapse
- TYPES =
Operation types based on XDiff and JATS-diff research
%i[ insert delete update move merge split upgrade downgrade ].freeze
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Check if two operations are equal.
-
#[](key) ⇒ Object?
Get a metadata value.
-
#initialize(type:, **metadata) ⇒ Operation
constructor
Initialize a new operation.
-
#inspect ⇒ String
Detailed string representation.
-
#to_s ⇒ String
String representation.
-
#type?(type) ⇒ Boolean
Check if operation is a specific type.
Constructor Details
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
32 33 34 |
# File 'lib/canon/tree_diff/operations/operation.rb', line 32 def @metadata end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
32 33 34 |
# File 'lib/canon/tree_diff/operations/operation.rb', line 32 def type @type end |
Instance Method Details
#==(other) ⇒ Boolean
Check if two operations are equal
67 68 69 70 71 |
# File 'lib/canon/tree_diff/operations/operation.rb', line 67 def ==(other) return false unless other.is_a?(Operation) type == other.type && == other. end |
#[](key) ⇒ Object?
Get a metadata value
59 60 61 |
# File 'lib/canon/tree_diff/operations/operation.rb', line 59 def [](key) @metadata[key] end |
#inspect ⇒ String
Detailed string representation
83 84 85 86 87 88 |
# File 'lib/canon/tree_diff/operations/operation.rb', line 83 def inspect = @metadata.map do |k, v| "#{k}: #{v.inspect}" end.join(", ") "#<#{self.class.name} type=#{type} #{}>" end |
#to_s ⇒ String
String representation
76 77 78 |
# File 'lib/canon/tree_diff/operations/operation.rb', line 76 def to_s "Operation(#{type})" end |
#type?(type) ⇒ Boolean
Check if operation is a specific type
51 52 53 |
# File 'lib/canon/tree_diff/operations/operation.rb', line 51 def type?(type) @type == type end |