Class: Telegram::TelegramChat
- Inherits:
-
TelegramBase
- Object
- TelegramBase
- Telegram::TelegramChat
- Defined in:
- lib/telegram/models.rb
Overview
Telegram Chat Model
Instance Attribute Summary collapse
-
#members ⇒ Array<TelegramContact>
readonly
The members of the chat.
-
#name ⇒ String
readonly
The name of the chat.
-
#type ⇒ String
readonly
The type of the chat (chat, encr_chat, user and etc).
Attributes inherited from TelegramBase
Instance Method Summary collapse
-
#initialize(client, chat) ⇒ TelegramChat
constructor
Create a new chat instance.
-
#leave! ⇒ Object
Leave from current chat.
-
#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, chat) ⇒ TelegramChat
Create a new chat instance
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/telegram/models.rb', line 162 def initialize(client, chat) @client = client @chat = chat @id = chat['peer_id'] @name = @title = chat.has_key?('title') ? chat['title'] : chat['print_name'] @type = chat['peer_type'] @members = [] if chat.has_key?('members') chat['members'].each { |user| @members << TelegramContact.pick_or_new(client, user) } elsif @type == 'user' and chat['user'] @members << TelegramContact.pick_or_new(client, chat) end end |
Instance Attribute Details
#members ⇒ Array<TelegramContact> (readonly)
Returns The members of the chat.
152 153 154 |
# File 'lib/telegram/models.rb', line 152 def members @members end |
#name ⇒ String (readonly)
Returns The name of the chat.
149 150 151 |
# File 'lib/telegram/models.rb', line 149 def name @name end |
#type ⇒ String (readonly)
Returns The type of the chat (chat, encr_chat, user and etc).
155 156 157 |
# File 'lib/telegram/models.rb', line 155 def type @type end |
Instance Method Details
#leave! ⇒ Object
Leave from current chat
183 184 185 |
# File 'lib/telegram/models.rb', line 183 def leave! @client.chat_del_user(self, @client.profile.to_tg) end |
#to_s ⇒ String
Convert Event instance to the string format
195 196 197 |
# File 'lib/telegram/models.rb', line 195 def to_s "<TelegramChat #{@title}(#{@type}\##{@id}) members=#{@members.size}>" end |
#to_tg ⇒ String
Returns A chat identifier formatted with type.
188 189 190 |
# File 'lib/telegram/models.rb', line 188 def to_tg "#{@type}\##{@id}" end |