Class: Yoda::AST::CommentBlock::TagPart

Inherits:
BasePart
  • Object
show all
Defined in:
lib/yoda/ast/comment_block/tag_part.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RangeCalculation

#begin_location, #end_location, #include?, #range, #text

Constructor Details

#initialize(comment_block:, token:) ⇒ TagPart

Returns a new instance of TagPart.

Parameters:



13
14
15
16
# File 'lib/yoda/ast/comment_block/tag_part.rb', line 13

def initialize(comment_block:, token:)
  @comment_block = comment_block
  @token = token
end

Instance Attribute Details

#comment_blockCommentBlock (readonly)

Returns:



6
7
8
# File 'lib/yoda/ast/comment_block/tag_part.rb', line 6

def comment_block
  @comment_block
end

#tokenParsing::CommentTokenizer::Sequence (readonly)



9
10
11
# File 'lib/yoda/ast/comment_block/tag_part.rb', line 9

def token
  @token
end

Instance Method Details

#begin_indexInteger

Returns:

  • (Integer)


19
20
21
# File 'lib/yoda/ast/comment_block/tag_part.rb', line 19

def begin_index
  token.all_tokens.first.offset
end

#end_indexInteger

Returns:

  • (Integer)


24
25
26
27
# File 'lib/yoda/ast/comment_block/tag_part.rb', line 24

def end_index
  last_token = token.all_tokens.last
  last_token.offset + last_token.length
end

#name_partTagTextNamePart?

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/yoda/ast/comment_block/tag_part.rb', line 38

def name_part
  @name_part ||= begin
    if tokens_before_bracket.empty?
      if tokens_after_bracket.empty?
        nil
      else
        TagTextNamePart.new(parent: self, tokens: [tokens_after_bracket.first])
      end
    else
      TagTextNamePart.new(parent: self, tokens: tokens_before_bracket)
    end
  end
end

#nearest_part(location) ⇒ BasePart

Parameters:

Returns:



54
55
56
# File 'lib/yoda/ast/comment_block/tag_part.rb', line 54

def nearest_part(location)
  [type_part, name_part, self].compact.find { |part| part.range.include?(location) }
end

#type_partTagTextTypePart?

Returns:



30
31
32
33
34
35
# File 'lib/yoda/ast/comment_block/tag_part.rb', line 30

def type_part
  return nil if tokens_in_bracket.empty?
  @type_part ||= begin
    TagTextTypePart.new(parent: self, tokens: tokens_in_bracket)
  end
end