Class: MessageEntity
- Inherits:
-
Object
- Object
- MessageEntity
- Defined in:
- lib/objects/message_entity.rb
Overview
Monday, August 24 2020 EAT
This object represents one special entity in a text message.
For example, hashtags, usernames, URLs, etc.
Instance Method Summary collapse
-
#bot_command? ⇒ Boolean
Returns true if entity #type is bot_command else false is returned.
-
#email? ⇒ Boolean
Returns true if entity #type is email else false is returned.
-
#initialize(msg) ⇒ MessageEntity
constructor
:nodoc:.
-
#language ⇒ Object
Optional.Forpreonly, the programming language of the entity text. -
#length ⇒ Object
Length of the entity in UTF-16 code units.
-
#link? ⇒ Boolean
Return true if entity #type is url else false is returned.
-
#mention? ⇒ Boolean
Returns true if entity #type is mention else false is returned.
-
#offset ⇒ Object
Offset in UTF-16 code units to the start of the entity.
-
#phone_number? ⇒ Boolean
Return true if entity #type is
phone_numberelse false is returned. -
#text_link? ⇒ Boolean
Returns true if entity #type is
text_linkelse false is returned. -
#text_mention? ⇒ Boolean
Returns true if entity #type is
text_mentionelse false is returned. -
#type ⇒ Object
Type of the entity.
-
#url ⇒ Object
Optional.Fortext_linkonly, url that will be opened after user taps on the text. -
#user ⇒ Object
Optional.
Constructor Details
#initialize(msg) ⇒ MessageEntity
:nodoc:
11 12 13 14 |
# File 'lib/objects/message_entity.rb', line 11 def initialize(msg) # :nodoc: @msg = msg freeze end |
Instance Method Details
#bot_command? ⇒ Boolean
Returns true if entity #type is bot_command else false is returned.
65 66 67 |
# File 'lib/objects/message_entity.rb', line 65 def bot_command? type.eql? 'bot_command' end |
#email? ⇒ Boolean
Returns true if entity #type is email else false is returned.
75 76 77 |
# File 'lib/objects/message_entity.rb', line 75 def email? type.eql? 'email' end |
#language ⇒ Object
Optional. For pre only, the programming language of the entity text.
46 47 48 |
# File 'lib/objects/message_entity.rb', line 46 def language @msg.language end |
#length ⇒ Object
Length of the entity in UTF-16 code units.
35 36 37 |
# File 'lib/objects/message_entity.rb', line 35 def length @msg.length end |
#link? ⇒ Boolean
Return true if entity #type is url else false is returned.
70 71 72 |
# File 'lib/objects/message_entity.rb', line 70 def link? type.elq? 'url' end |
#mention? ⇒ Boolean
Returns true if entity #type is mention else false is returned.
60 61 62 |
# File 'lib/objects/message_entity.rb', line 60 def mention? type.eql? 'mention' end |
#offset ⇒ Object
Offset in UTF-16 code units to the start of the entity.
30 31 32 |
# File 'lib/objects/message_entity.rb', line 30 def offset @msg.offset end |
#phone_number? ⇒ Boolean
Return true if entity #type is phone_number else false is returned.
80 81 82 |
# File 'lib/objects/message_entity.rb', line 80 def phone_number? type.eql? 'phone_number' end |
#text_link? ⇒ Boolean
Returns true if entity #type is text_link else false is returned.
85 86 87 |
# File 'lib/objects/message_entity.rb', line 85 def text_link? type.eql? 'text_link' end |
#text_mention? ⇒ Boolean
Returns true if entity #type is text_mention else false is returned.
90 91 92 |
# File 'lib/objects/message_entity.rb', line 90 def text_mention? type.eql? 'text_mention' end |
#type ⇒ Object
Type of the entity. Can be mention( @username ), hashtag( #hashtag ), cashtag( $USD ), bot_command( /start@jobs_bot ), url( telegram.org ), email( [email protected] ), phone_number( +1-212-555-0123 ), bold(bold text), italic(italic text), underline(underlined text), strikethrough(strikethrough text), code (monowidth string), pre (monowidth block), text_link(for clickable text URLs), text_mention (for users without usernames)
25 26 27 |
# File 'lib/objects/message_entity.rb', line 25 def type @msg.type end |
#url ⇒ Object
Optional. For text_link only, url that will be opened after user taps on the text.
41 42 43 |
# File 'lib/objects/message_entity.rb', line 41 def url @msg.url end |
#user ⇒ Object
Optional. For text_mention? only, the mentioned user. Returns User object
52 53 54 55 56 57 |
# File 'lib/objects/message_entity.rb', line 52 def user usr = @msg.user return User.new(usr) if usr false end |