class Telegram::TelegramContact

Attributes

name[R]
phone[R]
type[R]

Public Class Methods

new(client, contact) click to toggle source
# File lib/telegram/models.rb, line 82
def initialize(client, contact)
  @client = client
  @contact = contact

  @id = contact['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
pick_or_new(client, contact) click to toggle source
# File lib/telegram/models.rb, line 76
def self.pick_or_new(client, contact)
  ct = client.contacts.find { |c| c.id == contact['id'] }
  return ct unless ct.nil?
  TelegramContact.new(client, contact)
end

Public Instance Methods

chats() click to toggle source
# File lib/telegram/models.rb, line 95
def chats
  @client.chats.select { |c| c.member.include?(self) }
end
to_s() click to toggle source
# File lib/telegram/models.rb, line 103
def to_s
  "<TelegramContact #{@name}(#{@id}) username=#{@username}>"
end
to_tg() click to toggle source
# File lib/telegram/models.rb, line 99
def to_tg
  "#{@type}\##{@id}"
end