Class: MatrixSdk::MXID
Instance Attribute Summary collapse
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#localpart ⇒ Object
Returns the value of attribute localpart.
-
#port ⇒ Object
Returns the value of attribute port.
-
#sigil ⇒ Object
Returns the value of attribute sigil.
Instance Method Summary collapse
-
#event? ⇒ Boolean
Check if the ID is of a event.
-
#group? ⇒ Boolean
Check if the ID is of a group.
-
#initialize(identifier) ⇒ MXID
constructor
A new instance of MXID.
-
#room? ⇒ Boolean
Check if the ID is of a room.
-
#room_alias? ⇒ Boolean
Check if the ID is a room_alias.
-
#room_id? ⇒ Boolean
Check if the ID is a room_id.
- #to_s ⇒ Object
-
#type ⇒ Symbol
Returns the type of the ID.
-
#user? ⇒ Boolean
Check if the ID is of a user.
-
#valid? ⇒ Boolean
Checks if the ID is valid.
Constructor Details
#initialize(identifier) ⇒ MXID
Returns a new instance of MXID.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/matrix_sdk/mxid.rb', line 6 def initialize(identifier) raise ArugmentError, 'Identifier must be a String' unless identifier.is_a? String raise ArgumentError, 'Identifier is too long' if identifier.size > 255 raise ArgumentError, 'Identifier lacks required data' unless identifier =~ %r{^([@!$+#][^:]+:[^:]+(?::\d+)?)|(\$[A-Za-z0-9+/]+)$} @sigil = identifier[0] @localpart, @domain, @port = identifier[1..-1].split(':') raise ArgumentError, 'Identifier is not a valid MXID' unless valid? end |
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain.
3 4 5 |
# File 'lib/matrix_sdk/mxid.rb', line 3 def domain @domain end |
#localpart ⇒ Object
Returns the value of attribute localpart.
3 4 5 |
# File 'lib/matrix_sdk/mxid.rb', line 3 def localpart @localpart end |
#port ⇒ Object
Returns the value of attribute port.
3 4 5 |
# File 'lib/matrix_sdk/mxid.rb', line 3 def port @port end |
#sigil ⇒ Object
Returns the value of attribute sigil.
3 4 5 |
# File 'lib/matrix_sdk/mxid.rb', line 3 def sigil @sigil end |
Instance Method Details
#event? ⇒ Boolean
Check if the ID is of a event
66 67 68 |
# File 'lib/matrix_sdk/mxid.rb', line 66 def event? type == :event_id end |
#group? ⇒ Boolean
Check if the ID is of a group
54 55 56 |
# File 'lib/matrix_sdk/mxid.rb', line 54 def group? type == :group_id end |
#room? ⇒ Boolean
Check if the ID is of a room
60 61 62 |
# File 'lib/matrix_sdk/mxid.rb', line 60 def room? type == :room_id || type == :room_alias end |
#room_alias? ⇒ Boolean
Check if the ID is a room_alias
78 79 80 |
# File 'lib/matrix_sdk/mxid.rb', line 78 def room_alias? type == :room_alias end |
#room_id? ⇒ Boolean
Check if the ID is a room_id
72 73 74 |
# File 'lib/matrix_sdk/mxid.rb', line 72 def room_id? type == :room_id end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/matrix_sdk/mxid.rb', line 17 def to_s "#{sigil}#{localpart}#{domain ? ':' + domain : ''}" end |
#type ⇒ Symbol
Returns the type of the ID
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/matrix_sdk/mxid.rb', line 24 def type case sigil when '@' :user_id when '!' :room_id when '$' :event_id when '+' :group_id when '#' :room_alias end end |
#user? ⇒ Boolean
Check if the ID is of a user
48 49 50 |
# File 'lib/matrix_sdk/mxid.rb', line 48 def user? type == :user_id end |
#valid? ⇒ Boolean
Checks if the ID is valid
42 43 44 |
# File 'lib/matrix_sdk/mxid.rb', line 42 def valid? !type.nil? end |