Class: Inquirex::WidgetHint

Inherits:
Data
  • Object
show all
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.

Examples:

hint = WidgetHint.new(type: :radio_group, options: { columns: 2 })
hint.to_h  # => { "type" => "radio_group", "columns" => 2 }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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: options.transform_keys(&:to_sym).freeze)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



12
13
14
# File 'lib/inquirex/widget_hint.rb', line 12

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type

Returns:

  • (Object)

    the current value of 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).

Parameters:

  • hash (Hash)

Returns:



28
29
30
31
32
33
# File 'lib/inquirex/widget_hint.rb', line 28

def self.from_h(hash)
  type = hash["type"] || hash[:type]
  options = hash.reject { |k, _| k.to_s == "type" }
                .transform_keys(&:to_sym)
  new(type:, options:)
end

Instance Method Details

#to_hHash<String, Object>

Serializes to a flat hash: type key + option keys merged in.

Returns:

  • (Hash<String, Object>)


20
21
22
# File 'lib/inquirex/widget_hint.rb', line 20

def to_h
  { "type" => type.to_s }.merge(options.transform_keys(&:to_s))
end