Class: Telegem::Markup::InlineKeyboard
- Inherits:
-
Object
- Object
- Telegem::Markup::InlineKeyboard
- Defined in:
- lib/markup/keyboard.rb
Instance Attribute Summary collapse
-
#buttons ⇒ Object
readonly
Returns the value of attribute buttons.
Class Method Summary collapse
-
.[](*rows) ⇒ Object
Create from array.
-
.build(&block) ⇒ Object
Builder pattern.
Instance Method Summary collapse
-
#button(text, **options) ⇒ Object
Add a button.
-
#callback(text, data) ⇒ Object
Callback button.
-
#initialize(buttons = []) ⇒ InlineKeyboard
constructor
A new instance of InlineKeyboard.
-
#login(text, url, **options) ⇒ Object
Login button.
-
#row(*buttons) ⇒ Object
Add a row.
-
#switch_inline(text, query = "") ⇒ Object
Switch inline query button.
-
#switch_inline_current(text, query = "") ⇒ Object
Switch inline query current chat button.
-
#to_h ⇒ Object
Convert to Telegram format.
- #to_json(*args) ⇒ Object
-
#url(text, url) ⇒ Object
URL button.
-
#web_app(text, url) ⇒ Object
Web app button.
Constructor Details
#initialize(buttons = []) ⇒ InlineKeyboard
Returns a new instance of InlineKeyboard.
95 96 97 |
# File 'lib/markup/keyboard.rb', line 95 def initialize( = []) = end |
Instance Attribute Details
#buttons ⇒ Object (readonly)
Returns the value of attribute buttons.
93 94 95 |
# File 'lib/markup/keyboard.rb', line 93 def end |
Class Method Details
.[](*rows) ⇒ Object
Create from array
100 101 102 |
# File 'lib/markup/keyboard.rb', line 100 def self.[](*rows) new(rows) end |
.build(&block) ⇒ Object
Builder pattern
105 106 107 108 109 |
# File 'lib/markup/keyboard.rb', line 105 def self.build(&block) builder = InlineBuilder.new builder.instance_eval(&block) if block_given? builder.keyboard end |
Instance Method Details
#button(text, **options) ⇒ Object
Add a button
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/markup/keyboard.rb', line 118 def (text, **) last_row = .last || [] if last_row.is_a?(Array) last_row << { text: text }.merge() else << [{ text: text }.merge()] end self end |
#callback(text, data) ⇒ Object
Callback button
135 136 137 |
# File 'lib/markup/keyboard.rb', line 135 def callback(text, data) (text, callback_data: data) end |
#login(text, url, **options) ⇒ Object
Login button
145 146 147 |
# File 'lib/markup/keyboard.rb', line 145 def login(text, url, **) (text, login_url: { url: url, ** }) end |
#row(*buttons) ⇒ Object
Add a row
112 113 114 115 |
# File 'lib/markup/keyboard.rb', line 112 def row(*) << .flatten self end |
#switch_inline(text, query = "") ⇒ Object
Switch inline query button
150 151 152 |
# File 'lib/markup/keyboard.rb', line 150 def switch_inline(text, query = "") (text, switch_inline_query: query) end |
#switch_inline_current(text, query = "") ⇒ Object
Switch inline query current chat button
155 156 157 |
# File 'lib/markup/keyboard.rb', line 155 def switch_inline_current(text, query = "") (text, switch_inline_query_current_chat: query) end |
#to_h ⇒ Object
Convert to Telegram format
160 161 162 163 164 |
# File 'lib/markup/keyboard.rb', line 160 def to_h { inline_keyboard: .map { |row| row.is_a?(Array) ? row : [row] } } end |
#to_json(*args) ⇒ Object
166 167 168 |
# File 'lib/markup/keyboard.rb', line 166 def to_json(*args) to_h.to_json(*args) end |
#url(text, url) ⇒ Object
URL button
130 131 132 |
# File 'lib/markup/keyboard.rb', line 130 def url(text, url) (text, url: url) end |
#web_app(text, url) ⇒ Object
Web app button
140 141 142 |
# File 'lib/markup/keyboard.rb', line 140 def web_app(text, url) (text, web_app: { url: url }) end |