Class: Yoda::AST::CommentBlock
- Inherits:
-
Object
- Object
- Yoda::AST::CommentBlock
show all
- Defined in:
- lib/yoda/ast/comment_block.rb,
lib/yoda/ast/comment_block/token.rb,
lib/yoda/ast/comment_block/tag_part.rb,
lib/yoda/ast/comment_block/base_part.rb,
lib/yoda/ast/comment_block/text_part.rb,
lib/yoda/ast/comment_block/range_calculation.rb,
lib/yoda/ast/comment_block/tag_text_name_part.rb,
lib/yoda/ast/comment_block/tag_text_type_part.rb
Defined Under Namespace
Modules: RangeCalculation
Classes: BasePart, TagPart, TagTextNamePart, TagTextTypePart, TextPart, Token
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(comments, node: nil) ⇒ CommentBlock
Returns a new instance of CommentBlock.
34
35
36
37
|
# File 'lib/yoda/ast/comment_block.rb', line 34
def initialize(, node: nil)
@comments = Array()
@node = node
end
|
Instance Attribute Details
27
28
29
|
# File 'lib/yoda/ast/comment_block.rb', line 27
def
@comments
end
|
30
31
32
|
# File 'lib/yoda/ast/comment_block.rb', line 30
def node
@node
end
|
Class Method Details
.build_part(comment_block:, token:) ⇒ BasePart
Instance Method Details
#build_part(token) ⇒ BasePart
86
87
88
|
# File 'lib/yoda/ast/comment_block.rb', line 86
def build_part(token)
self.class.build_part(comment_block: self, token: token)
end
|
66
67
68
69
70
|
# File 'lib/yoda/ast/comment_block.rb', line 66
def location_from_index(index)
partial_text = text.slice(::Range.new(0, index))
*lines_before, curent_line = partial_text.split("\n", -1)
begin_location&.move(row: lines_before.length, column: curent_line&.length || 0)
end
|
#nearest_part(location) ⇒ BasePart?
53
54
55
|
# File 'lib/yoda/ast/comment_block.rb', line 53
def nearest_part(location)
parts.find { |part| part.include?(location) }
end
|
#nearest_tag_part(location) ⇒ TagPart?
59
60
61
62
|
# File 'lib/yoda/ast/comment_block.rb', line 59
def nearest_tag_part(location)
part = nearest_part(location)
part&.is_a?(TagPart) ? part : nil
end
|
#offset_from_location(location) ⇒ Integer?
74
75
76
77
78
79
80
81
82
|
# File 'lib/yoda/ast/comment_block.rb', line 74
def offset_from_location(location)
if begin_location
row_diff = location.row - begin_location.row
column_diff = location.column - begin_location.column
lines = text.split("\n", -1)
lines.slice(0, row_diff).join("\n").length + column_diff
end
end
|
45
46
47
48
49
|
# File 'lib/yoda/ast/comment_block.rb', line 45
def parts
@parts ||= parsed_tokens.map do |token|
build_part(token)
end
end
|
103
104
105
106
107
108
109
|
# File 'lib/yoda/ast/comment_block.rb', line 103
def range
if begin_location && end_location
Parsing::Range.new(begin_location, end_location)
else
nil
end
end
|
#text ⇒ String
40
41
42
|
# File 'lib/yoda/ast/comment_block.rb', line 40
def text
.map(&:text).join
end
|