Class: Telegem::Markup::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/markup/keyboard.rb

Overview

Builder DSL for keyboards

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



175
176
177
# File 'lib/markup/keyboard.rb', line 175

def initialize
  @keyboard = Keyboard.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



195
196
197
198
199
200
201
# File 'lib/markup/keyboard.rb', line 195

def method_missing(name, *args, &block)
  if @keyboard.respond_to?(name)
    @keyboard.send(name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#keyboardObject (readonly)

Returns the value of attribute keyboard.



173
174
175
# File 'lib/markup/keyboard.rb', line 173

def keyboard
  @keyboard
end

Instance Method Details

#button(text, **options) ⇒ Object



190
191
192
193
# File 'lib/markup/keyboard.rb', line 190

def button(text, **options)
  @keyboard.button(text, **options)
  self
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


203
204
205
# File 'lib/markup/keyboard.rb', line 203

def respond_to_missing?(name, include_private = false)
  @keyboard.respond_to?(name) || super
end

#row(*buttons, &block) ⇒ Object



179
180
181
182
183
184
185
186
187
188
# File 'lib/markup/keyboard.rb', line 179

def row(*buttons, &block)
  if block_given?
    sub_builder = Builder.new
    sub_builder.instance_eval(&block)
    @keyboard.row(*sub_builder.keyboard.buttons.flatten(1))
  else
    @keyboard.row(*buttons)
  end
  self
end