Class: Lkml::Tree::BlockNode

Inherits:
SyntaxNode show all
Defined in:
lib/lkml/tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, left_brace: nil, right_brace: nil, colon: nil, name: nil, container: nil) ⇒ BlockNode

Returns a new instance of BlockNode.



353
354
355
356
357
358
359
360
361
362
# File 'lib/lkml/tree.rb', line 353

def initialize(type:, left_brace: nil, right_brace: nil, colon: nil, name: nil, container: nil)
  super()
  @type = type
  @left_brace = left_brace || LeftCurlyBrace.new("{", nil, "", "\n")
  @right_brace = right_brace || RightCurlyBrace.new("}", nil, "\n", "")
  @colon = colon || Colon.new(":", nil, "", " ")
  @name = name
  @container = container || ContainerNode.new(items: [])
  freeze
end

Instance Attribute Details

#colonObject (readonly)

Returns the value of attribute colon.



351
352
353
# File 'lib/lkml/tree.rb', line 351

def colon
  @colon
end

#containerObject (readonly)

Returns the value of attribute container.



351
352
353
# File 'lib/lkml/tree.rb', line 351

def container
  @container
end

#left_braceObject (readonly)

Returns the value of attribute left_brace.



351
352
353
# File 'lib/lkml/tree.rb', line 351

def left_brace
  @left_brace
end

#nameObject (readonly)

Returns the value of attribute name.



351
352
353
# File 'lib/lkml/tree.rb', line 351

def name
  @name
end

#right_braceObject (readonly)

Returns the value of attribute right_brace.



351
352
353
# File 'lib/lkml/tree.rb', line 351

def right_brace
  @right_brace
end

#typeObject (readonly)

Returns the value of attribute type.



351
352
353
# File 'lib/lkml/tree.rb', line 351

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



398
399
400
401
402
403
404
405
406
# File 'lib/lkml/tree.rb', line 398

def ==(other)
  instance_of?(other.class) &&
    @type == other.type &&
    @left_brace == other.left_brace &&
    @right_brace == other.right_brace &&
    @colon == other.colon &&
    @name == other.name &&
    @container == other.container
end

#accept(visitor) ⇒ Object



377
378
379
# File 'lib/lkml/tree.rb', line 377

def accept(visitor)
  visitor.visit_block(self)
end

#childrenObject



369
370
371
# File 'lib/lkml/tree.rb', line 369

def children
  @container.children
end

#inspectObject



364
365
366
367
# File 'lib/lkml/tree.rb', line 364

def inspect
  nm = @name ? "name='#{@name.value}'" : "None"
  "#{self.class.name.split('::').last}(type='#{@type.value}', #{nm})"
end

#line_numberObject



373
374
375
# File 'lib/lkml/tree.rb', line 373

def line_number
  @type.line_number
end

#to_sObject



381
382
383
384
385
# File 'lib/lkml/tree.rb', line 381

def to_s
  nm = @name || ""
  ctr = @container || ""
  Tree.items_to_str(@type, @colon, nm, @left_brace, ctr, @right_brace)
end

#with(**changes) ⇒ Object



387
388
389
390
391
392
393
394
395
396
# File 'lib/lkml/tree.rb', line 387

def with(**changes)
  BlockNode.new(
    type: changes.fetch(:type, @type),
    left_brace: changes.fetch(:left_brace, @left_brace),
    right_brace: changes.fetch(:right_brace, @right_brace),
    colon: changes.fetch(:colon, @colon),
    name: changes.fetch(:name, @name),
    container: changes.fetch(:container, @container)
  )
end