Class: Kernai::Block
- Inherits:
-
Object
- Object
- Kernai::Block
- Defined in:
- lib/kernai/block.rb
Constant Summary collapse
- TYPES =
%i[command json final plan result error].freeze
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type:, content:, name: nil) ⇒ Block
constructor
A new instance of Block.
- #to_h ⇒ Object
Constructor Details
#initialize(type:, content:, name: nil) ⇒ Block
Returns a new instance of Block.
9 10 11 12 13 |
# File 'lib/kernai/block.rb', line 9 def initialize(type:, content:, name: nil) @type = type.to_sym @name = name @content = content end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
7 8 9 |
# File 'lib/kernai/block.rb', line 7 def content @content end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/kernai/block.rb', line 7 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/kernai/block.rb', line 7 def type @type end |
Class Method Details
.define(type, &handler) ⇒ Object
22 23 24 |
# File 'lib/kernai/block.rb', line 22 def define(type, &handler) handlers[type.to_sym] = handler end |
.handler_for(type) ⇒ Object
26 27 28 |
# File 'lib/kernai/block.rb', line 26 def handler_for(type) handlers[type.to_sym] end |
.reset_handlers! ⇒ Object
30 31 32 |
# File 'lib/kernai/block.rb', line 30 def reset_handlers! @handlers = {} end |
Instance Method Details
#to_h ⇒ Object
15 16 17 18 19 |
# File 'lib/kernai/block.rb', line 15 def to_h h = { type: @type, content: @content } h[:name] = @name if @name h end |