Class: GenerativeUI::Component

Inherits:
Data
  • Object
show all
Defined in:
lib/generative_ui/component.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes

Returns:

  • (Object)

    the current value of attributes



4
5
6
# File 'lib/generative_ui/component.rb', line 4

def attributes
  @attributes
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



4
5
6
# File 'lib/generative_ui/component.rb', line 4

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



4
5
6
# File 'lib/generative_ui/component.rb', line 4

def name
  @name
end

Class Method Details

.from_raw(raw) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/generative_ui/component.rb', line 5

def self.from_raw(raw)
  raw = {} unless raw.is_a?(Hash)
  id = raw["id"] || raw[:id]
  name = raw["component"] || raw[:component]
  attributes = raw.each_with_object({}) do |(key, value), memo|
    next if %w[id component].include?(key.to_s)

    memo[key.to_s] = value
  end

  new(id:, name:, attributes:)
end

Instance Method Details

#to_hObject



18
19
20
# File 'lib/generative_ui/component.rb', line 18

def to_h
  { "id" => id, "component" => name, **attributes }
end