Class: Warb::Components::ReplyButtonAction

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buttons_texts: []) ⇒ ReplyButtonAction

Returns a new instance of ReplyButtonAction.



78
79
80
# File 'lib/warb/components/action.rb', line 78

def initialize(buttons_texts: [])
  @buttons_texts = buttons_texts
end

Instance Attribute Details

#buttons_textsObject

Returns the value of attribute buttons_texts.



76
77
78
# File 'lib/warb/components/action.rb', line 76

def buttons_texts
  @buttons_texts
end

Instance Method Details

#add_button_text(button_text) ⇒ Object

rubocop:enable Metrics/MethodLength



101
102
103
# File 'lib/warb/components/action.rb', line 101

def add_button_text(button_text)
  @buttons_texts << button_text
end

#to_hObject

rubocop:disable Metrics/MethodLength



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/warb/components/action.rb', line 83

def to_h
  {
    buttons: @buttons_texts.map.with_index do |button_text, index|
      text = button_text.normalize.gsub(/\s/, '').downcase
      id = "#{text}_#{index}"

      {
        type: 'reply',
        reply: {
          id: id,
          title: button_text
        }
      }
    end
  }
end