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].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.



410
411
412
413
414
415
416
417
418
# File 'lib/api/types.rb', line 410

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



438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/api/types.rb', line 438

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
  else
    nil
  end
end

#typeObject



420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
# File 'lib/api/types.rb', line 420

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
  :unknown
end