Class: Warb::Components::Section

Inherits:
Object
  • Object
show all
Defined in:
lib/warb/components/action.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#rowsObject

Returns the value of attribute rows.



22
23
24
# File 'lib/warb/components/action.rb', line 22

def rows
  @rows
end

#titleObject

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_hObject



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