Class: TreeHaver::Backends::Prism::Comment

Inherits:
TreeHaver::Base::Comment show all
Defined in:
lib/tree_haver/backends/prism.rb

Overview

Prism comment wrapper.

Prism exposes native Ruby comments via Prism::Comment subclasses and Prism::Location objects. This wrapper normalizes those objects onto a small parser-facing contract for downstream consumers.

Constant Summary

Constants inherited from TreeHaver::Base::Comment

TreeHaver::Base::Comment::ATTACHMENT_HINTS

Instance Attribute Summary

Attributes inherited from TreeHaver::Base::Comment

#attachment_hint, #inner_comment, #source

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TreeHaver::Base::Comment

#at_file_end?, #at_file_start?, #attachment_hint?, #blank_line_count_after, #blank_line_count_before, #blank_lines_after, #blank_lines_before, #block?, #body_text, #closing_delimiter, #delimiter_metadata, #end_line, #initialize, #inline?, #inspect, #leading?, #line?, #multiline?, #normalized_text, #source_position, #start_line, #trailing?

Constructor Details

This class inherits a constructor from TreeHaver::Base::Comment

Class Method Details

.comment_type_for(klass) ⇒ Object



368
369
370
371
372
# File 'lib/tree_haver/backends/prism.rb', line 368

def comment_type_for(klass)
  klass.name.split('::').last
       .gsub(/([a-z\d])([A-Z])/, '\\1_\\2')
       .downcase
end

Instance Method Details

#end_byteObject



341
342
343
# File 'lib/tree_haver/backends/prism.rb', line 341

def end_byte
  location.end_offset
end

#end_pointObject



352
353
354
355
356
357
# File 'lib/tree_haver/backends/prism.rb', line 352

def end_point
  {
    row: location.end_line - 1,
    column: location.end_column
  }
end

#locationObject



325
326
327
# File 'lib/tree_haver/backends/prism.rb', line 325

def location
  inner_comment.location
end

#opening_delimiterObject



363
364
365
# File 'lib/tree_haver/backends/prism.rb', line 363

def opening_delimiter
  '#'
end

#start_byteObject



337
338
339
# File 'lib/tree_haver/backends/prism.rb', line 337

def start_byte
  location.start_offset
end

#start_pointObject



345
346
347
348
349
350
# File 'lib/tree_haver/backends/prism.rb', line 345

def start_point
  {
    row: location.start_line - 1,
    column: location.start_column
  }
end

#styleObject



359
360
361
# File 'lib/tree_haver/backends/prism.rb', line 359

def style
  :line
end

#textObject



333
334
335
# File 'lib/tree_haver/backends/prism.rb', line 333

def text
  inner_comment.slice
end

#typeObject



329
330
331
# File 'lib/tree_haver/backends/prism.rb', line 329

def type
  self.class.comment_type_for(inner_comment.class)
end