Class: Telegem::Types::User

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

Constant Summary collapse

COMMON_FIELDS =
%w[id is_bot first_name last_name username
can_join_groups can_read_all_group_messages 
supports_inline_queries language_code 
is_premium added_to_attachment_menu 
can_connect_to_business].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

Constructor Details

#initialize(data) ⇒ User

Returns a new instance of User.



96
97
98
99
100
101
102
# File 'lib/api/types.rb', line 96

def initialize(data)
  super(data)
  
  COMMON_FIELDS.each do |field|
    define_accessor(field.to_sym)
  end
end

Dynamic Method Handling

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

Instance Method Details

#full_nameObject



104
105
106
# File 'lib/api/types.rb', line 104

def full_name
  [first_name, last_name].compact.join(' ')
end

#mentionObject



108
109
110
111
112
113
114
115
116
# File 'lib/api/types.rb', line 108

def mention
  if username
    "@#{username}"
  elsif first_name
    first_name
  else
    "User ##{id}"
  end
end

#to_sObject



118
119
120
# File 'lib/api/types.rb', line 118

def to_s
  full_name
end