Class: Warb::Components::Section
- Inherits:
-
Object
- Object
- Warb::Components::Section
- Defined in:
- lib/warb/components/action.rb
Instance Attribute Summary collapse
-
#rows ⇒ Object
Returns the value of attribute rows.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #add_row(**args) ⇒ Object
-
#initialize(title: nil, rows: []) ⇒ Section
constructor
A new instance of Section.
- #to_h ⇒ Object
Constructor Details
#initialize(title: nil, rows: []) ⇒ Section
Returns a new instance of Section.
24 25 26 27 |
# File 'lib/warb/components/action.rb', line 24 def initialize(title: nil, rows: []) @title = title @rows = rows end |
Instance Attribute Details
#rows ⇒ Object
Returns the value of attribute rows.
22 23 24 |
# File 'lib/warb/components/action.rb', line 22 def rows @rows end |
#title ⇒ Object
Returns the value of attribute title.
22 23 24 |
# File 'lib/warb/components/action.rb', line 22 def title @title end |
Instance Method Details
#add_row(**args) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/warb/components/action.rb', line 29 def add_row(**args, &) row = Row.new(**args) @rows << row block_given? ? row.tap(&) : row end |
#to_h ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/warb/components/action.rb', line 37 def to_h { title: @title, rows: @rows.map.with_index do |row, index| row_title = row.title.slice(0, 10) title = row_title.normalize.gsub(/\s/, '').downcase id = "#{title}_#{index}" row.to_h.merge(id: id) end } end |