Class: Lkml::Tree::ListNode
- Inherits:
-
SyntaxNode
- Object
- SyntaxNode
- Lkml::Tree::ListNode
- Defined in:
- lib/lkml/tree.rb
Instance Attribute Summary collapse
-
#colon ⇒ Object
readonly
Returns the value of attribute colon.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#leading_comma ⇒ Object
readonly
Returns the value of attribute leading_comma.
-
#left_bracket ⇒ Object
readonly
Returns the value of attribute left_bracket.
-
#right_bracket ⇒ Object
readonly
Returns the value of attribute right_bracket.
-
#trailing_comma ⇒ Object
readonly
Returns the value of attribute trailing_comma.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #children ⇒ Object
-
#initialize(type:, items:, left_bracket:, right_bracket:, colon: nil, leading_comma: nil, trailing_comma: nil) ⇒ ListNode
constructor
A new instance of ListNode.
- #inspect ⇒ Object
- #line_number ⇒ Object
- #to_s ⇒ Object
- #with(**changes) ⇒ Object
Constructor Details
#initialize(type:, items:, left_bracket:, right_bracket:, colon: nil, leading_comma: nil, trailing_comma: nil) ⇒ ListNode
Returns a new instance of ListNode.
231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/lkml/tree.rb', line 231 def initialize(type:, items:, left_bracket:, right_bracket:, colon: nil, leading_comma: nil, trailing_comma: nil) super() @type = type @items = items.freeze @left_bracket = left_bracket @right_bracket = right_bracket @colon = colon || Colon.new(":", nil, "", " ") @leading_comma = leading_comma @trailing_comma = trailing_comma freeze end |
Instance Attribute Details
#colon ⇒ Object (readonly)
Returns the value of attribute colon.
229 230 231 |
# File 'lib/lkml/tree.rb', line 229 def colon @colon end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
229 230 231 |
# File 'lib/lkml/tree.rb', line 229 def items @items end |
#leading_comma ⇒ Object (readonly)
Returns the value of attribute leading_comma.
229 230 231 |
# File 'lib/lkml/tree.rb', line 229 def leading_comma @leading_comma end |
#left_bracket ⇒ Object (readonly)
Returns the value of attribute left_bracket.
229 230 231 |
# File 'lib/lkml/tree.rb', line 229 def left_bracket @left_bracket end |
#right_bracket ⇒ Object (readonly)
Returns the value of attribute right_bracket.
229 230 231 |
# File 'lib/lkml/tree.rb', line 229 def right_bracket @right_bracket end |
#trailing_comma ⇒ Object (readonly)
Returns the value of attribute trailing_comma.
229 230 231 |
# File 'lib/lkml/tree.rb', line 229 def trailing_comma @trailing_comma end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
229 230 231 |
# File 'lib/lkml/tree.rb', line 229 def type @type end |
Instance Method Details
#==(other) ⇒ Object
281 282 283 284 285 286 287 288 289 290 |
# File 'lib/lkml/tree.rb', line 281 def ==(other) instance_of?(other.class) && @type == other.type && @items == other.items && @left_bracket == other.left_bracket && @right_bracket == other.right_bracket && @colon == other.colon && @leading_comma == other.leading_comma && @trailing_comma == other.trailing_comma end |
#accept(visitor) ⇒ Object
258 259 260 |
# File 'lib/lkml/tree.rb', line 258 def accept(visitor) visitor.visit_list(self) end |
#children ⇒ Object
248 249 250 251 252 |
# File 'lib/lkml/tree.rb', line 248 def children return [].freeze if @items.empty? @items.first.is_a?(PairNode) ? @items : [] end |
#inspect ⇒ Object
244 245 246 |
# File 'lib/lkml/tree.rb', line 244 def inspect "#{self.class.name.split('::').last}(type='#{@type.value}')" end |
#line_number ⇒ Object
254 255 256 |
# File 'lib/lkml/tree.rb', line 254 def line_number @type.line_number end |
#to_s ⇒ Object
262 263 264 265 266 267 |
# File 'lib/lkml/tree.rb', line 262 def to_s mid = @items.join(",") lc = @leading_comma && !@items.empty? ? @leading_comma.to_s : "" tc = @trailing_comma && !@items.empty? ? @trailing_comma.to_s : "" Tree.items_to_str(@type, @colon, @left_bracket, lc, mid, tc, @right_bracket) end |
#with(**changes) ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/lkml/tree.rb', line 269 def with(**changes) ListNode.new( type: changes.fetch(:type, @type), items: changes.fetch(:items, @items), left_bracket: changes.fetch(:left_bracket, @left_bracket), right_bracket: changes.fetch(:right_bracket, @right_bracket), colon: changes.fetch(:colon, @colon), leading_comma: changes.fetch(:leading_comma, @leading_comma), trailing_comma: changes.fetch(:trailing_comma, @trailing_comma) ) end |