Class: Rubord::Components::Container
- Inherits:
-
BaseComponent
- Object
- BaseComponent
- Rubord::Components::Container
- Defined in:
- lib/rubord/components/containers/container.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#components ⇒ Object
readonly
Returns the value of attribute components.
Attributes inherited from BaseComponent
Instance Method Summary collapse
- #add(component) ⇒ Object
-
#initialize(*components, color: nil) ⇒ Container
constructor
A new instance of Container.
- #to_h ⇒ Object
Constructor Details
#initialize(*components, color: nil) ⇒ Container
Returns a new instance of Container.
8 9 10 11 12 13 |
# File 'lib/rubord/components/containers/container.rb', line 8 def initialize(*components, color: nil) super(17) @color = Rubord.Parser.color(color) @components = [] components.compact.each { |c| add(c) } end |
Instance Attribute Details
#color ⇒ Object (readonly)
Returns the value of attribute color.
6 7 8 |
# File 'lib/rubord/components/containers/container.rb', line 6 def color @color end |
#components ⇒ Object (readonly)
Returns the value of attribute components.
6 7 8 |
# File 'lib/rubord/components/containers/container.rb', line 6 def components @components end |
Instance Method Details
#add(component) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/rubord/components/containers/container.rb', line 15 def add(component) unless component.respond_to?(:to_h) raise ArgumentError, "Invalid component inside Container: #{component.inspect}" end @components << component self end |
#to_h ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/rubord/components/containers/container.rb', line 24 def to_h payload = { type: @type, components: @components.map(&:to_h).compact } payload[:accent_color] = @color if @color payload end |