Class: Keyboard::KeyboardButton
- Inherits:
-
Object
- Object
- Keyboard::KeyboardButton
- Defined in:
- lib/vk_cozy/dev/keyboard/button.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get_data ⇒ Object
-
#initialize(action, color: nil, data: nil) ⇒ KeyboardButton
constructor
A new instance of KeyboardButton.
Constructor Details
#initialize(action, color: nil, data: nil) ⇒ KeyboardButton
Returns a new instance of KeyboardButton.
3 4 5 6 7 |
# File 'lib/vk_cozy/dev/keyboard/button.rb', line 3 def initialize(action, color: nil, data: nil) @action = action @color = color @data = data end |
Class Method Details
.from_hash(data) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/vk_cozy/dev/keyboard/button.rb', line 13 def self.from_hash(data) color = data.key('color') keyboard_data = {'action' => data} if color.nil? keyboard_data['action'].delete('color') keyboard_data['color'] = color end return self.new(self.action, self.color, keyboard_data) end |
.from_typed(action, color: nil) ⇒ Object
9 10 11 |
# File 'lib/vk_cozy/dev/keyboard/button.rb', line 9 def self.from_typed(action, color: nil) return self.new(action, color: color, data: nil) end |
Instance Method Details
#get_data ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/vk_cozy/dev/keyboard/button.rb', line 23 def get_data if not @data.nil? return @data end data = {'action' => @action.get_data()} if ['text', 'callback'].include?(@action.type) and not @color.nil? data['color'] = @color end return data end |