Class: Telegram::TelegramContact
- Inherits:
-
TelegramBase
- Object
- TelegramBase
- Telegram::TelegramContact
- Defined in:
- lib/telegram/models.rb
Overview
Telegram Contact Model
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The name of the contact.
-
#phone ⇒ Array<TelegramContact>
readonly
The phone number of the contact.
-
#type ⇒ String
readonly
The type of the contact # => “user”.
-
#username ⇒ String
readonly
The username of the contact.
Attributes inherited from TelegramBase
Instance Method Summary collapse
-
#chats ⇒ Array<TelegramChat>
Chats that contact participates.
-
#initialize(client, contact) ⇒ TelegramContact
constructor
Create a new contact instance.
-
#to_s ⇒ String
Convert Event instance to the string format.
-
#to_tg ⇒ String
A chat identifier formatted with type.
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
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
#name ⇒ String (readonly)
Returns The name of the contact.
206 207 208 |
# File 'lib/telegram/models.rb', line 206 def name @name end |
#phone ⇒ Array<TelegramContact> (readonly)
Returns The phone number of the contact.
212 213 214 |
# File 'lib/telegram/models.rb', line 212 def phone @phone end |
#type ⇒ String (readonly)
Returns The type of the contact # => “user”.
215 216 217 |
# File 'lib/telegram/models.rb', line 215 def type @type end |
#username ⇒ String (readonly)
Returns The username of the contact.
209 210 211 |
# File 'lib/telegram/models.rb', line 209 def username @username end |
Instance Method Details
#chats ⇒ Array<TelegramChat>
Returns Chats that contact participates.
237 238 239 |
# File 'lib/telegram/models.rb', line 237 def chats @client.chats.select { |c| c.member.include?(self) } end |
#to_s ⇒ String
Convert Event instance to the string format
249 250 251 |
# File 'lib/telegram/models.rb', line 249 def to_s "<TelegramContact #{@name}(#{@id}) username=#{@username}>" end |
#to_tg ⇒ String
Returns A chat identifier formatted with type.
242 243 244 |
# File 'lib/telegram/models.rb', line 242 def to_tg "#{@type}\##{@id}" end |