Class: Telegram::TelegramContact
- Inherits:
-
TelegramBase
- Object
- TelegramBase
- Telegram::TelegramContact
- Defined in:
- lib/telegram/models.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#phone ⇒ Object
readonly
Returns the value of attribute phone.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from TelegramBase
Class Method Summary collapse
Instance Method Summary collapse
- #chats ⇒ Object
-
#initialize(client, contact) ⇒ TelegramContact
constructor
A new instance of TelegramContact.
- #to_s ⇒ Object
- #to_tg ⇒ Object
Methods inherited from TelegramBase
#send_image, #send_image_url, #send_message, #send_sticker
Constructor Details
#initialize(client, contact) ⇒ TelegramContact
Returns a new instance of TelegramContact.
82 83 84 85 86 87 88 89 90 91 92 93 |
# 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 |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
72 73 74 |
# File 'lib/telegram/models.rb', line 72 def name @name end |
#phone ⇒ Object (readonly)
Returns the value of attribute phone.
73 74 75 |
# File 'lib/telegram/models.rb', line 73 def phone @phone end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
74 75 76 |
# File 'lib/telegram/models.rb', line 74 def type @type end |
Class Method Details
.pick_or_new(client, contact) ⇒ Object
76 77 78 79 80 |
# 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 |
Instance Method Details
#chats ⇒ Object
95 96 97 |
# File 'lib/telegram/models.rb', line 95 def chats @client.chats.select { |c| c.member.include?(self) } end |
#to_s ⇒ Object
103 104 105 |
# File 'lib/telegram/models.rb', line 103 def to_s "<TelegramContact #{@name}(#{@id}) username=#{@username}>" end |
#to_tg ⇒ Object
99 100 101 |
# File 'lib/telegram/models.rb', line 99 def to_tg "#{@type}\##{@id}" end |