class Yoda::Parsing::Query::CurrentCommentQuery
Provides helper methods to find the current comment which means the comment on the current position.
Attributes
Public Class Methods
@param comments [Array<::Parser::Source::Comment>] @param location [Location] represents the current position.
# File lib/yoda/parsing/query/current_comment_query.rb, line 10 def initialize(comments, location) fail ArgumentError, comments unless comments.all? { |comment| comment.is_a?(::Parser::Source::Comment) } fail ArgumentError, location unless location.is_a?(Location) @comments = comments @location = location end
Public Instance Methods
Calculate absolute position from the relative position. @param position [Location]
# File lib/yoda/parsing/query/current_comment_query.rb, line 50 def absolute_position(position) position.move(row: current_comment_block.first.location.line - 1, column: current_comment_block.first.location.column) end
Calculate absolute range from the relative range. @param range [Range]
# File lib/yoda/parsing/query/current_comment_query.rb, line 62 def absolute_range(range) range.move(row: current_comment_block.first.location.line - 1, column: current_comment_block.first.location.column) end
@return [Location]
# File lib/yoda/parsing/query/current_comment_query.rb, line 36 def begin_point_of_current_comment_block Location.new(row: current_comment_block.first.location.line, column: current_comment_block.first.location.column) end
The single line comment which the current position is on. @return [::Parser::Source::Comment, nil]
# File lib/yoda/parsing/query/current_comment_query.rb, line 19 def current_comment @current_comment ||= comments.find { |comment| location.included?(comment.location) } end
The multiple line comments which the current position is on. @return [Array<::Parser::Source::Comment>]
# File lib/yoda/parsing/query/current_comment_query.rb, line 25 def current_comment_block @current_comment_block ||= current_comment ? comment_blocks.find { |block| block.include?(current_comment) } : [] end
@return [String]
# File lib/yoda/parsing/query/current_comment_query.rb, line 67 def current_comment_block_text current_comment_block.map(&:text).join("\n") end
The relative coordinates of the current position from the beginning position of the current comment. @return [Location]
# File lib/yoda/parsing/query/current_comment_query.rb, line 31 def location_in_current_comment_block relative_position(location) end
Calculate relative position (the coordinates from the beginning point) from the relative position. @param position [Location]
# File lib/yoda/parsing/query/current_comment_query.rb, line 44 def relative_position(position) position.move(row: 1 - current_comment_block.first.location.line, column: - current_comment_block.first.location.column) end
Calculate relative range from the relative range. @param range [Range]
# File lib/yoda/parsing/query/current_comment_query.rb, line 56 def relative_range(range) range.move(row: 1 - current_comment_block.first.location.line, column: - current_comment_block.first.location.column) end
Private Instance Methods
@return [Array<Array<::Parser::Source::Comment>>]
# File lib/yoda/parsing/query/current_comment_query.rb, line 74 def comment_blocks @comment_blocks ||= comments.chunk_while { |i, j| i.location.line + 1 == j.location.line } end