Class: Wcl::BlockRef
- Inherits:
-
Object
- Object
- Wcl::BlockRef
- Defined in:
- lib/wcl/types.rb
Overview
A reference to a WCL block with its attributes.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#decorators ⇒ Object
readonly
Returns the value of attribute decorators.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #get(key) ⇒ Object
- #has_decorator?(name) ⇒ Boolean
-
#initialize(kind:, id: nil, attributes: {}, children: [], decorators: []) ⇒ BlockRef
constructor
A new instance of BlockRef.
- #inspect ⇒ Object (also: #to_s)
- #to_h ⇒ Object
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
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/wcl/types.rb', line 4 def attributes @attributes end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
4 5 6 |
# File 'lib/wcl/types.rb', line 4 def children @children end |
#decorators ⇒ Object (readonly)
Returns the value of attribute decorators.
4 5 6 |
# File 'lib/wcl/types.rb', line 4 def decorators @decorators end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/wcl/types.rb', line 4 def id @id end |
#kind ⇒ Object (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
22 23 24 |
# File 'lib/wcl/types.rb', line 22 def has_decorator?(name) @decorators.any? { |d| d.name == name } end |
#inspect ⇒ Object 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_h ⇒ Object
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 |