Class: Telegem::Types::Update

Inherits:
BaseType
  • Object
show all
Defined in:
lib/api/types.rb

Constant Summary collapse

COMMON_FIELDS =
%w[update_id message edited_message channel_post
edited_channel_post inline_query chosen_inline_result
callback_query shipping_query pre_checkout_query
poll poll_answer my_chat_member chat_member
chat_join_request managed_bot_created managed_bot].freeze

Instance Attribute Summary

Attributes inherited from BaseType

#_raw_data

Instance Method Summary collapse

Methods inherited from BaseType

#inspect, #method_missing, #respond_to_missing?, #to_h, #to_s

Constructor Details

#initialize(data) ⇒ Update

Returns a new instance of Update.



414
415
416
417
418
419
420
421
422
# File 'lib/api/types.rb', line 414

def initialize(data)
  super(data)

  COMMON_FIELDS.each do |field|
    define_accessor(field.to_sym)
  end

  convert_update_objects
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Telegem::Types::BaseType

Instance Method Details

#fromObject



444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'lib/api/types.rb', line 444

def from
  case type
  when :message, :edited_message
    message.from
  when :channel_post, :edited_channel_post
    channel_post.from
  when :inline_query
    inline_query.from
  when :chosen_inline_result
    chosen_inline_result.from
  when :callback_query
    callback_query.from
  when :shipping_query
    shipping_query.from
  when :pre_checkout_query
    pre_checkout_query.from
  when :my_chat_member, :chat_member
    my_chat_member&.from || chat_member&.from
  when :chat_join_request
    chat_join_request.from
  when :managed_bot_created, :managed_bot
    managed_bot_created&.from || managed_bot&.from
  else
    nil
  end
end

#typeObject



424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/api/types.rb', line 424

def type
  return :message if message
  return :edited_message if edited_message
  return :channel_post if channel_post
  return :edited_channel_post if edited_channel_post
  return :inline_query if inline_query
  return :chosen_inline_result if chosen_inline_result
  return :callback_query if callback_query
  return :shipping_query if shipping_query
  return :pre_checkout_query if pre_checkout_query
  return :poll if poll
  return :poll_answer if poll_answer
  return :my_chat_member if my_chat_member
  return :chat_member if chat_member
  return :chat_join_request if chat_join_request
  return :managed_bot_created if managed_bot_created
  return :managed_bot if managed_bot
  :unknown
end