Class: Inquirex::WidgetHint
- Inherits:
-
Data
- Object
- Data
- Inquirex::WidgetHint
- Defined in:
- lib/inquirex/widget_hint.rb
Overview
Immutable rendering hint attached to a step node. Carries a widget type (e.g. :radio_group) and an optional options hash (e.g. { columns: 2 }). Framework-agnostic — consumed by the JS widget, TTY adapter, or any other frontend renderer.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.from_h(hash) ⇒ WidgetHint
Deserializes from a plain hash (string or symbol keys).
Instance Method Summary collapse
-
#initialize(type:, options: {}) ⇒ WidgetHint
constructor
A new instance of WidgetHint.
-
#to_h ⇒ Hash<String, Object>
Serializes to a flat hash: type key + option keys merged in.
Constructor Details
#initialize(type:, options: {}) ⇒ WidgetHint
Returns a new instance of WidgetHint.
13 14 15 |
# File 'lib/inquirex/widget_hint.rb', line 13 def initialize(type:, options: {}) super(type: type.to_sym, options: .transform_keys(&:to_sym).freeze) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options
12 13 14 |
# File 'lib/inquirex/widget_hint.rb', line 12 def @options end |
#type ⇒ Object (readonly)
Returns the value of attribute type
12 13 14 |
# File 'lib/inquirex/widget_hint.rb', line 12 def type @type end |
Class Method Details
.from_h(hash) ⇒ WidgetHint
Deserializes from a plain hash (string or symbol keys).
28 29 30 31 32 33 |
# File 'lib/inquirex/widget_hint.rb', line 28 def self.from_h(hash) type = hash["type"] || hash[:type] = hash.reject { |k, _| k.to_s == "type" } .transform_keys(&:to_sym) new(type:, options:) end |
Instance Method Details
#to_h ⇒ Hash<String, Object>
Serializes to a flat hash: type key + option keys merged in.
20 21 22 |
# File 'lib/inquirex/widget_hint.rb', line 20 def to_h { "type" => type.to_s }.merge(.transform_keys(&:to_s)) end |