Class: Ast::Crispr::Match
- Inherits:
-
Object
- Object
- Ast::Crispr::Match
- Defined in:
- lib/ast/crispr.rb
Instance Attribute Summary collapse
-
#end_line ⇒ Object
readonly
Returns the value of attribute end_line.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#start_line ⇒ Object
readonly
Returns the value of attribute start_line.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(start_line:, end_line:, target: nil, node: nil, metadata: {}, **options) ⇒ Match
constructor
A new instance of Match.
- #line_range ⇒ Object
- #match_profile ⇒ Object
- #slice_from(content) ⇒ Object
- #with_target(target) ⇒ Object
Constructor Details
#initialize(start_line:, end_line:, target: nil, node: nil, metadata: {}, **options) ⇒ Match
Returns a new instance of Match.
126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/ast/crispr.rb', line 126 def initialize(start_line:, end_line:, target: nil, node: nil, metadata: {}, **) @target = target @node = node @start_line = Integer(start_line) @end_line = Integer(end_line) @metadata = .merge() return unless @end_line < @start_line raise Error.new('CRISPR match end_line must be >= start_line', details: { start_line: @start_line, end_line: @end_line }) end |
Instance Attribute Details
#end_line ⇒ Object (readonly)
Returns the value of attribute end_line.
124 125 126 |
# File 'lib/ast/crispr.rb', line 124 def end_line @end_line end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
124 125 126 |
# File 'lib/ast/crispr.rb', line 124 def @metadata end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
124 125 126 |
# File 'lib/ast/crispr.rb', line 124 def node @node end |
#start_line ⇒ Object (readonly)
Returns the value of attribute start_line.
124 125 126 |
# File 'lib/ast/crispr.rb', line 124 def start_line @start_line end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
124 125 126 |
# File 'lib/ast/crispr.rb', line 124 def target @target end |
Instance Method Details
#line_range ⇒ Object
150 151 152 |
# File 'lib/ast/crispr.rb', line 150 def line_range start_line..end_line end |
#match_profile ⇒ Object
161 162 163 164 165 166 167 168 |
# File 'lib/ast/crispr.rb', line 161 def match_profile MatchProfile.new( start_boundary: .fetch(:start_boundary, :owner_start), end_boundary: .fetch(:end_boundary, :owner_end), payload_kind: .fetch(:payload_kind, :structural_owner_body), metadata: ) end |
#slice_from(content) ⇒ Object
154 155 156 157 158 159 |
# File 'lib/ast/crispr.rb', line 154 def slice_from(content) lines = content.to_s.lines return '' if lines.empty? lines[(start_line - 1)..(end_line - 1)].to_a.join end |
#with_target(target) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/ast/crispr.rb', line 138 def with_target(target) return self if self.target.equal?(target) self.class.new( target: target, node: node, start_line: start_line, end_line: end_line, metadata: ) end |