Class: XNM::Telegram::KeyboardLayout
- Inherits:
-
Object
- Object
- XNM::Telegram::KeyboardLayout
- Defined in:
- lib/xnm/telegram/KeyboardLayout.rb
Instance Method Summary collapse
- #[](i) ⇒ Object
- #ilk_reply_markup ⇒ Object
-
#initialize(start_config = nil) ⇒ KeyboardLayout
constructor
A new instance of KeyboardLayout.
- #set_button(name, command = nil, c: 0, r: 0) ⇒ Object
- #to_ilk_layout ⇒ Object
Constructor Details
#initialize(start_config = nil) ⇒ KeyboardLayout
Returns a new instance of KeyboardLayout.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/xnm/telegram/KeyboardLayout.rb', line 5 def initialize(start_config = nil) @rows = Array.new() if start_config.is_a? Hash start_config = [start_config] end if start_config.is_a? Array start_config.each_index do |i| j = 0 start_config[i].each do |k, v| (k, v, r: i, c: j) j += 1 end end end end |
Instance Method Details
#[](i) ⇒ Object
23 24 25 |
# File 'lib/xnm/telegram/KeyboardLayout.rb', line 23 def [](i) @rows[i] end |
#ilk_reply_markup ⇒ Object
41 42 43 |
# File 'lib/xnm/telegram/KeyboardLayout.rb', line 41 def ilk_reply_markup() return { inline_keyboard: to_ilk_layout } end |
#set_button(name, command = nil, c: 0, r: 0) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/xnm/telegram/KeyboardLayout.rb', line 27 def (name, command = nil, c: 0, r: 0) command ||= name @rows[r] ||= []; = {text: name} if command =~ /^(http|tg)/ [:url] = command else [:callback_data] = command end @rows[r][c] = end |
#to_ilk_layout ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/xnm/telegram/KeyboardLayout.rb', line 45 def to_ilk_layout() out_data = []; @rows.each do |row| next if row.nil? next if row.empty? formatted_row = [] row.each do || next if .nil? formatted_row << end out_data << formatted_row unless formatted_row.empty? end out_data end |