Class: Warb::Components::ListAction

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(button_text: nil, sections: []) ⇒ ListAction

Returns a new instance of ListAction.



54
55
56
57
# File 'lib/warb/components/action.rb', line 54

def initialize(button_text: nil, sections: [])
  @button_text = button_text
  @sections = sections
end

Instance Attribute Details

#button_textObject

Returns the value of attribute button_text.



52
53
54
# File 'lib/warb/components/action.rb', line 52

def button_text
  @button_text
end

#sectionsObject

Returns the value of attribute sections.



52
53
54
# File 'lib/warb/components/action.rb', line 52

def sections
  @sections
end

Instance Method Details

#add_section(**args) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/warb/components/action.rb', line 59

def add_section(**args, &)
  section = Section.new(**args)

  @sections << section

  block_given? ? section.tap(&) : section
end

#to_hObject



67
68
69
70
71
72
# File 'lib/warb/components/action.rb', line 67

def to_h
  {
    button: @button_text,
    sections: @sections.map(&:to_h)
  }
end