Class: RailsOpenapiGen::Parsers::Jbuilder::PropertyCommentParser

Inherits:
Object
  • Object
show all
Defined in:
lib/rails-openapi-gen/parsers/jbuilder/property_comment_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(comments) ⇒ PropertyCommentParser

Initializes property comment parser

Parameters:

  • comments (Array)

    Array of comment objects



9
10
11
12
# File 'lib/rails-openapi-gen/parsers/jbuilder/property_comment_parser.rb', line 9

def initialize(comments)
  @comments = comments
  @comment_parser = RailsOpenapiGen::Parsers::CommentParser.new
end

Instance Method Details

#find_property_comment_for_line(line_number) ⇒ Hash?

Finds property comment for a specific line

Parameters:

  • line_number (Integer)

    Line number to find comment for

Returns:

  • (Hash, nil)

    Parsed comment data or nil



17
18
19
20
21
22
23
24
# File 'lib/rails-openapi-gen/parsers/jbuilder/property_comment_parser.rb', line 17

def find_property_comment_for_line(line_number)
  @comments.reverse.find do |comment|
    comment_line = comment.location.line
    comment_line == line_number - 1 || comment_line == line_number
  end&.then do |comment|
    @comment_parser.parse(comment.text)
  end
end