Class: Yoda::Parsing::Query::CurrentCommentTokenQuery
- Inherits:
-
Object
- Object
- Yoda::Parsing::Query::CurrentCommentTokenQuery
- Defined in:
- lib/yoda/parsing/query/current_comment_token_query.rb
Overview
Provides helper methods to find the current comment token (token on current position) and its kind.
Defined Under Namespace
Classes: InputtingLine
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#location_in_comment ⇒ Object
readonly
Returns the value of attribute location_in_comment.
Instance Method Summary collapse
- #at_sign? ⇒ true, false
- #current_line_comment ⇒ String
- #current_range ⇒ Range?
- #current_state ⇒ Symbol
- #current_word ⇒ String?
-
#initialize(comment, location_in_comment) ⇒ CurrentCommentTokenQuery
constructor
A new instance of CurrentCommentTokenQuery.
Constructor Details
#initialize(comment, location_in_comment) ⇒ CurrentCommentTokenQuery
Returns a new instance of CurrentCommentTokenQuery.
10 11 12 13 14 15 |
# File 'lib/yoda/parsing/query/current_comment_token_query.rb', line 10 def initialize(comment, location_in_comment) fail ArgumentError, comment unless comment.is_a?(String) fail ArgumentError, location_in_comment unless location_in_comment.is_a?(Location) @comment = comment @location_in_comment = location_in_comment end |
Instance Attribute Details
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
6 7 8 |
# File 'lib/yoda/parsing/query/current_comment_token_query.rb', line 6 def comment @comment end |
#location_in_comment ⇒ Object (readonly)
Returns the value of attribute location_in_comment.
6 7 8 |
# File 'lib/yoda/parsing/query/current_comment_token_query.rb', line 6 def location_in_comment @location_in_comment end |
Instance Method Details
#at_sign? ⇒ true, false
42 43 44 |
# File 'lib/yoda/parsing/query/current_comment_token_query.rb', line 42 def at_sign? inputting_line.at_sign? end |
#current_line_comment ⇒ String
18 19 20 |
# File 'lib/yoda/parsing/query/current_comment_token_query.rb', line 18 def current_line_comment comment.split("\n")[location_in_comment.row - 1] || '' end |
#current_range ⇒ Range?
35 36 37 38 39 |
# File 'lib/yoda/parsing/query/current_comment_token_query.rb', line 35 def current_range return nil if !inputting_line || !inputting_line.current_range start, last = inputting_line.current_range Range.new(Location.new(row: location_in_comment.row, column: start), Location.new(row: location_in_comment.row, column: last)) end |
#current_state ⇒ Symbol
23 24 25 26 |
# File 'lib/yoda/parsing/query/current_comment_token_query.rb', line 23 def current_state return :none unless inputting_line inputting_line.current_state end |
#current_word ⇒ String?
29 30 31 32 |
# File 'lib/yoda/parsing/query/current_comment_token_query.rb', line 29 def current_word return nil unless inputting_line inputting_line.current_token.to_s end |