Class: Ast::Crispr::MatchProfile

Inherits:
Object
  • Object
show all
Includes:
ProfileReportCompatibility
Defined in:
lib/ast/crispr.rb,
lib/ast/crispr.rb

Constant Summary collapse

KNOWN_START_BOUNDARIES =
{
  owner_start: {
    family: :structural_owner,
    description: "Span starts at the structural owner's boundary"
  },
  comment_region_start: {
    family: :comment_anchor,
    description: 'Span starts at an owning comment-region boundary'
  }
}.freeze
KNOWN_END_BOUNDARIES =
{
  owner_end: {
    family: :structural_owner,
    description: "Span ends at the structural owner's boundary"
  },
  owner_end_plus_trailing_gap: {
    family: :gap_extension,
    description: 'Span extends past the owner boundary to include trailing blank-line gap'
  }
}.freeze
KNOWN_PAYLOAD_KINDS =
{
  structural_owner_body: {
    family: :owner_body,
    description: "Span represents a structural owner's body"
  },
  comment_owned_body: {
    family: :comment_owned,
    description: 'Span represents a structural owner body selected through an owning comment marker'
  },
  section_branch: {
    family: :section_branch,
    description: 'Span represents a heading-owned section branch payload'
  }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_boundary:, end_boundary:, payload_kind:, metadata: {}, **options) ⇒ MatchProfile

Returns a new instance of MatchProfile.



209
210
211
212
213
214
# File 'lib/ast/crispr.rb', line 209

def initialize(start_boundary:, end_boundary:, payload_kind:, metadata: {}, **options)
  @start_boundary = normalize_start_boundary(start_boundary)
  @end_boundary = normalize_end_boundary(end_boundary)
  @payload_kind = normalize_payload_kind(payload_kind)
  @metadata = .merge(options).freeze
end

Instance Attribute Details

#end_boundaryObject (readonly)

Returns the value of attribute end_boundary.



207
208
209
# File 'lib/ast/crispr.rb', line 207

def end_boundary
  @end_boundary
end

#metadataObject (readonly)

Returns the value of attribute metadata.



207
208
209
# File 'lib/ast/crispr.rb', line 207

def 
  @metadata
end

#payload_kindObject (readonly)

Returns the value of attribute payload_kind.



207
208
209
# File 'lib/ast/crispr.rb', line 207

def payload_kind
  @payload_kind
end

#start_boundaryObject (readonly)

Returns the value of attribute start_boundary.



207
208
209
# File 'lib/ast/crispr.rb', line 207

def start_boundary
  @start_boundary
end

Instance Method Details

#comment_anchored?Boolean

Returns:

  • (Boolean)


252
253
254
# File 'lib/ast/crispr.rb', line 252

def comment_anchored?
  start_boundary == :comment_region_start
end

#comment_owned_body?Boolean

Returns:

  • (Boolean)


264
265
266
# File 'lib/ast/crispr.rb', line 264

def comment_owned_body?
  payload_kind == :comment_owned_body
end

#end_boundary_familyObject



228
229
230
# File 'lib/ast/crispr.rb', line 228

def end_boundary_family
  &.fetch(:family, nil)
end

#end_boundary_metadataObject



220
221
222
# File 'lib/ast/crispr.rb', line 220

def 
  KNOWN_END_BOUNDARIES[end_boundary]&.dup&.freeze
end

#known_end_boundary?Boolean

Returns:

  • (Boolean)


236
237
238
# File 'lib/ast/crispr.rb', line 236

def known_end_boundary?
  KNOWN_END_BOUNDARIES.key?(end_boundary)
end

#known_payload_kind?Boolean

Returns:

  • (Boolean)


248
249
250
# File 'lib/ast/crispr.rb', line 248

def known_payload_kind?
  KNOWN_PAYLOAD_KINDS.key?(payload_kind)
end

#known_start_boundary?Boolean

Returns:

  • (Boolean)


232
233
234
# File 'lib/ast/crispr.rb', line 232

def known_start_boundary?
  KNOWN_START_BOUNDARIES.key?(start_boundary)
end

#payload_familyObject



244
245
246
# File 'lib/ast/crispr.rb', line 244

def payload_family
  &.fetch(:family, nil)
end

#payload_kind_metadataObject



240
241
242
# File 'lib/ast/crispr.rb', line 240

def 
  KNOWN_PAYLOAD_KINDS[payload_kind]&.dup&.freeze
end

#reportObject



1589
1590
1591
1592
1593
1594
1595
1596
# File 'lib/ast/crispr.rb', line 1589

def report
  data = to_h.merge(
    start_boundary_family: start_boundary_family || :unknown,
    end_boundary_family: end_boundary_family || :unknown,
    payload_family: payload_family || :unknown
  )
  stringified_report(data)
end

#section_branch?Boolean

Returns:

  • (Boolean)


268
269
270
# File 'lib/ast/crispr.rb', line 268

def section_branch?
  payload_kind == :section_branch
end

#start_boundary_familyObject



224
225
226
# File 'lib/ast/crispr.rb', line 224

def start_boundary_family
  &.fetch(:family, nil)
end

#start_boundary_metadataObject



216
217
218
# File 'lib/ast/crispr.rb', line 216

def 
  KNOWN_START_BOUNDARIES[start_boundary]&.dup&.freeze
end

#structural_owner_body?Boolean

Returns:

  • (Boolean)


260
261
262
# File 'lib/ast/crispr.rb', line 260

def structural_owner_body?
  payload_kind == :structural_owner_body
end

#to_hObject



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/ast/crispr.rb', line 272

def to_h
  {
    start_boundary: start_boundary,
    start_boundary_family: start_boundary_family,
    known_start_boundary: known_start_boundary?,
    end_boundary: end_boundary,
    end_boundary_family: end_boundary_family,
    known_end_boundary: known_end_boundary?,
    payload_kind: payload_kind,
    payload_family: payload_family,
    known_payload_kind: known_payload_kind?,
    comment_anchored: comment_anchored?,
    trailing_gap_extended: trailing_gap_extended?,
    metadata: 
  }
end

#trailing_gap_extended?Boolean

Returns:

  • (Boolean)


256
257
258
# File 'lib/ast/crispr.rb', line 256

def trailing_gap_extended?
  end_boundary == :owner_end_plus_trailing_gap
end