Class: Telegem::Markup::Keyboard
- Inherits:
-
Object
- Object
- Telegem::Markup::Keyboard
- Defined in:
- lib/markup/keyboard.rb
Instance Attribute Summary collapse
-
#buttons ⇒ Object
readonly
Returns the value of attribute buttons.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.[](*rows) ⇒ Object
Create from array.
-
.build(&block) ⇒ Object
Builder pattern.
-
.force_reply(selective: false, input_field_placeholder: nil) ⇒ Object
Force reply.
-
.remove(selective: false) ⇒ Object
Remove keyboard.
Instance Method Summary collapse
-
#button(text, **options) ⇒ Object
Add a button.
-
#initialize(buttons = [], **options) ⇒ Keyboard
constructor
A new instance of Keyboard.
- #one_time(one_time = true) ⇒ Object
-
#resize(resize = true) ⇒ Object
Chainable options.
-
#row(*buttons) ⇒ Object
Add a row.
- #selective(selective = true) ⇒ Object
-
#to_h ⇒ Object
Convert to Telegram format.
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(buttons = [], **options) ⇒ Keyboard
6 7 8 9 10 11 12 13 |
# File 'lib/markup/keyboard.rb', line 6 def initialize( = [], **) = = { resize_keyboard: true, one_time_keyboard: false, selective: false }.merge() end |
Instance Attribute Details
#buttons ⇒ Object (readonly)
Returns the value of attribute buttons.
4 5 6 |
# File 'lib/markup/keyboard.rb', line 4 def end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/markup/keyboard.rb', line 4 def end |
Class Method Details
.[](*rows) ⇒ Object
Create from array
16 17 18 |
# File 'lib/markup/keyboard.rb', line 16 def self.[](*rows) new(rows) end |
.build(&block) ⇒ Object
Builder pattern
21 22 23 24 25 |
# File 'lib/markup/keyboard.rb', line 21 def self.build(&block) builder = Builder.new builder.instance_eval(&block) if block_given? builder.keyboard end |
.force_reply(selective: false, input_field_placeholder: nil) ⇒ Object
Force reply
82 83 84 85 86 87 88 89 |
# File 'lib/markup/keyboard.rb', line 82 def self.force_reply(selective: false, input_field_placeholder: nil) markup = { force_reply: true, selective: selective } markup[:input_field_placeholder] = input_field_placeholder if input_field_placeholder markup end |
.remove(selective: false) ⇒ Object
Remove keyboard
74 75 76 77 78 79 |
# File 'lib/markup/keyboard.rb', line 74 def self.remove(selective: false) { remove_keyboard: true, selective: selective } end |
Instance Method Details
#button(text, **options) ⇒ Object
Add a button
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/markup/keyboard.rb', line 34 def (text, **) last_row = .last || [] if last_row.is_a?(Array) last_row << { text: text }.merge() else << [{ text: text }.merge()] end self end |
#one_time(one_time = true) ⇒ Object
51 52 53 54 |
# File 'lib/markup/keyboard.rb', line 51 def one_time(one_time = true) [:one_time_keyboard] = one_time self end |
#resize(resize = true) ⇒ Object
Chainable options
46 47 48 49 |
# File 'lib/markup/keyboard.rb', line 46 def resize(resize = true) [:resize_keyboard] = resize self end |
#row(*buttons) ⇒ Object
Add a row
28 29 30 31 |
# File 'lib/markup/keyboard.rb', line 28 def row(*) << .flatten self end |
#selective(selective = true) ⇒ Object
56 57 58 59 |
# File 'lib/markup/keyboard.rb', line 56 def selective(selective = true) [:selective] = selective self end |
#to_h ⇒ Object
Convert to Telegram format
62 63 64 65 66 67 |
# File 'lib/markup/keyboard.rb', line 62 def to_h { keyboard: .map { |row| row.is_a?(Array) ? row : [row] }, ** } end |
#to_json(*args) ⇒ Object
69 70 71 |
# File 'lib/markup/keyboard.rb', line 69 def to_json(*args) to_h.to_json(*args) end |