Class: Wcl::BlockRef

Inherits:
Object
  • Object
show all
Defined in:
lib/wcl/types.rb

Overview

A reference to a WCL block with its attributes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind:, id: nil, attributes: {}, children: [], decorators: []) ⇒ BlockRef

Returns a new instance of BlockRef.



6
7
8
9
10
11
12
# File 'lib/wcl/types.rb', line 6

def initialize(kind:, id: nil, attributes: {}, children: [], decorators: [])
  @kind = kind
  @id = id
  @attributes = attributes
  @children = children
  @decorators = decorators
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



4
5
6
# File 'lib/wcl/types.rb', line 4

def attributes
  @attributes
end

#childrenObject (readonly)

Returns the value of attribute children.



4
5
6
# File 'lib/wcl/types.rb', line 4

def children
  @children
end

#decoratorsObject (readonly)

Returns the value of attribute decorators.



4
5
6
# File 'lib/wcl/types.rb', line 4

def decorators
  @decorators
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/wcl/types.rb', line 4

def id
  @id
end

#kindObject (readonly)

Returns the value of attribute kind.



4
5
6
# File 'lib/wcl/types.rb', line 4

def kind
  @kind
end

Instance Method Details

#[](key) ⇒ Object



18
19
20
# File 'lib/wcl/types.rb', line 18

def [](key)
  @attributes[key]
end

#get(key) ⇒ Object



14
15
16
# File 'lib/wcl/types.rb', line 14

def get(key)
  @attributes[key]
end

#has_decorator?(name) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/wcl/types.rb', line 22

def has_decorator?(name)
  @decorators.any? { |d| d.name == name }
end

#inspectObject Also known as: to_s



36
37
38
39
40
41
42
# File 'lib/wcl/types.rb', line 36

def inspect
  if @id
    "#<Wcl::BlockRef(#{@kind} #{@id})>"
  else
    "#<Wcl::BlockRef(#{@kind})>"
  end
end

#to_hObject



26
27
28
29
30
31
32
33
34
# File 'lib/wcl/types.rb', line 26

def to_h
  {
    kind: @kind,
    id: @id,
    attributes: @attributes,
    children: @children.map(&:to_h),
    decorators: @decorators.map(&:to_h)
  }
end