Class: Yoda::Parsing::Query::CurrentCommentQuery
- Inherits:
-
Object
- Object
- Yoda::Parsing::Query::CurrentCommentQuery
- Defined in:
- lib/yoda/parsing/query/current_comment_query.rb
Overview
Provides helper methods to find the current comment which means the comment on the current position.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
Returns the value of attribute comments.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
Coordinate conversion collapse
-
#absolute_position(position) ⇒ Object
Calculate absolute position from the relative position.
-
#absolute_range(range) ⇒ Object
Calculate absolute range from the relative range.
- #current_comment_block_text ⇒ String
-
#relative_position(position) ⇒ Object
Calculate relative position (the coordinates from the beginning point) from the relative position.
-
#relative_range(range) ⇒ Object
Calculate relative range from the relative range.
Instance Method Summary collapse
- #begin_point_of_current_comment_block ⇒ Location
-
#current_comment ⇒ ::Parser::Source::Comment?
The single line comment which the current position is on.
-
#current_comment_block ⇒ Array<::Parser::Source::Comment>
The multiple line comments which the current position is on.
-
#initialize(comments, location) ⇒ CurrentCommentQuery
constructor
A new instance of CurrentCommentQuery.
-
#location_in_current_comment_block ⇒ Location
The relative coordinates of the current position from the beginning position of the current comment.
Constructor Details
#initialize(comments, location) ⇒ CurrentCommentQuery
Returns a new instance of CurrentCommentQuery.
10 11 12 13 14 15 |
# 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 |
Instance Attribute Details
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
6 7 8 |
# File 'lib/yoda/parsing/query/current_comment_query.rb', line 6 def comments @comments end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
6 7 8 |
# File 'lib/yoda/parsing/query/current_comment_query.rb', line 6 def location @location end |
Instance Method Details
#absolute_position(position) ⇒ Object
Calculate absolute position from the relative position.
50 51 52 |
# 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 |
#absolute_range(range) ⇒ Object
Calculate absolute range from the relative range.
62 63 64 |
# 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 |
#begin_point_of_current_comment_block ⇒ Location
36 37 38 |
# 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 |
#current_comment ⇒ ::Parser::Source::Comment?
The single line comment which the current position is on.
19 20 21 |
# File 'lib/yoda/parsing/query/current_comment_query.rb', line 19 def current_comment @current_comment ||= comments.find { |comment| location.included?(comment.location) } end |
#current_comment_block ⇒ Array<::Parser::Source::Comment>
The multiple line comments which the current position is on.
25 26 27 |
# 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 |
#current_comment_block_text ⇒ String
67 68 69 |
# File 'lib/yoda/parsing/query/current_comment_query.rb', line 67 def current_comment_block_text current_comment_block.map(&:text).join("\n") end |
#location_in_current_comment_block ⇒ Location
The relative coordinates of the current position from the beginning position of the current comment.
31 32 33 |
# File 'lib/yoda/parsing/query/current_comment_query.rb', line 31 def location_in_current_comment_block relative_position(location) end |
#relative_position(position) ⇒ Object
Calculate relative position (the coordinates from the beginning point) from the relative position.
44 45 46 |
# 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 |
#relative_range(range) ⇒ Object
Calculate relative range from the relative range.
56 57 58 |
# 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 |