Class: Telegram::TelegramContact

Inherits:
TelegramBase show all
Defined in:
lib/telegram/models.rb

Overview

Telegram Contact Model

See Also:

Since:

  • 0.1.0

Instance Attribute Summary collapse

Attributes inherited from TelegramBase

#client, #id

Instance Method Summary collapse

Methods inherited from TelegramBase

#fail_back, pick_or_new, #send_image, #send_image_url, #send_message, #send_sticker, #send_typing, #send_typing_abort, #send_video, #targetize

Methods included from Logging

configure_logger_for, #logger, logger_for

Constructor Details

#initialize(client, contact) ⇒ TelegramContact

Create a new contact instance

Parameters:

  • client (Client)

    Root client instance

  • contact (Integer)

    Raw chat contact

Since:

  • 0.1.0


222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/telegram/models.rb', line 222

def initialize(client, contact)
  @client = client
  @contact = contact

  @id = contact['peer_id']
  @type = 'user'
  @username = contact.has_key?('username') ? contact['username'] : ''
  @name = contact['print_name']
  @phone = contact.has_key?('phone') ? contact['phone'] : ''

  @client.contacts << self unless @client.contacts.include?(self)
end

Instance Attribute Details

#nameString (readonly)

Returns The name of the contact.

Returns:

  • (String)

    The name of the contact

Since:

  • 0.1.0


206
207
208
# File 'lib/telegram/models.rb', line 206

def name
  @name
end

#phoneArray<TelegramContact> (readonly)

Returns The phone number of the contact.

Returns:

Since:

  • 0.1.0


212
213
214
# File 'lib/telegram/models.rb', line 212

def phone
  @phone
end

#typeString (readonly)

Returns The type of the contact # => “user”.

Returns:

  • (String)

    The type of the contact # => “user”

Since:

  • 0.1.0


215
216
217
# File 'lib/telegram/models.rb', line 215

def type
  @type
end

#usernameString (readonly)

Returns The username of the contact.

Returns:

  • (String)

    The username of the contact

Since:

  • 0.1.0


209
210
211
# File 'lib/telegram/models.rb', line 209

def username
  @username
end

Instance Method Details

#chatsArray<TelegramChat>

Returns Chats that contact participates.

Returns:

Since:

  • 0.1.0


237
238
239
# File 'lib/telegram/models.rb', line 237

def chats
  @client.chats.select { |c| c.member.include?(self) }
end

#to_sString

Convert Event instance to the string format

Returns:

Since:

  • 0.1.0


249
250
251
# File 'lib/telegram/models.rb', line 249

def to_s
  "<TelegramContact #{@name}(#{@id}) username=#{@username}>"
end

#to_tgString

Returns A chat identifier formatted with type.

Returns:

  • (String)

    A chat identifier formatted with type

Since:

  • 0.1.0


242
243
244
# File 'lib/telegram/models.rb', line 242

def to_tg
  "#{@type}\##{@id}"
end