Class: Zui::Node
- Inherits:
-
Object
- Object
- Zui::Node
- Defined in:
- lib/zui/node.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#props ⇒ Object
readonly
Returns the value of attribute props.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type:, id:, props: {}) ⇒ Node
constructor
A new instance of Node.
- #subscribe(event) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(type:, id:, props: {}) ⇒ Node
Returns a new instance of Node.
7 8 9 10 11 12 13 |
# File 'lib/zui/node.rb', line 7 def initialize(type:, id:, props: {}) @type = type.to_s @id = id.to_s @props = props.transform_keys(&:to_s) @children = [] @events = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
5 6 7 |
# File 'lib/zui/node.rb', line 5 def children @children end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
5 6 7 |
# File 'lib/zui/node.rb', line 5 def events @events end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/zui/node.rb', line 5 def id @id end |
#props ⇒ Object (readonly)
Returns the value of attribute props.
5 6 7 |
# File 'lib/zui/node.rb', line 5 def props @props end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/zui/node.rb', line 5 def type @type end |
Instance Method Details
#subscribe(event) ⇒ Object
23 24 25 |
# File 'lib/zui/node.rb', line 23 def subscribe(event) @events << event.to_s unless @events.include?(event.to_s) end |
#to_h ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/zui/node.rb', line 15 def to_h result = { "type" => type, "id" => id } result["props"] = props unless props.empty? result["children"] = children.map(&:to_h) unless children.empty? result["events"] = events unless events.empty? result end |