Class: GenerativeUI::ComponentSet
- Inherits:
-
Object
- Object
- GenerativeUI::ComponentSet
- Defined in:
- lib/generative_ui/component_set.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
Class Method Summary collapse
Instance Method Summary collapse
- #by_id ⇒ Object
- #duplicate_ids ⇒ Object
- #fetch(id) ⇒ Object
- #ids ⇒ Object
-
#initialize(components) ⇒ ComponentSet
constructor
A new instance of ComponentSet.
- #root ⇒ Object
Constructor Details
#initialize(components) ⇒ ComponentSet
Returns a new instance of ComponentSet.
11 12 13 |
# File 'lib/generative_ui/component_set.rb', line 11 def initialize(components) @components = components end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
5 6 7 |
# File 'lib/generative_ui/component_set.rb', line 5 def components @components end |
Class Method Details
Instance Method Details
#by_id ⇒ Object
15 16 17 18 19 |
# File 'lib/generative_ui/component_set.rb', line 15 def by_id @by_id ||= components.each_with_object({}) do |component, index| index[component.id] ||= component end end |
#duplicate_ids ⇒ Object
33 34 35 |
# File 'lib/generative_ui/component_set.rb', line 33 def duplicate_ids ids.compact.group_by(&:itself).select { |_id, entries| entries.size > 1 }.keys end |
#fetch(id) ⇒ Object
25 26 27 |
# File 'lib/generative_ui/component_set.rb', line 25 def fetch(id) by_id.fetch(id) end |
#ids ⇒ Object
29 30 31 |
# File 'lib/generative_ui/component_set.rb', line 29 def ids components.map(&:id) end |
#root ⇒ Object
21 22 23 |
# File 'lib/generative_ui/component_set.rb', line 21 def root by_id["root"] end |