Module: Blather::Stanza::Presence::Status::InstanceMethods
- Included in:
- Blather::Stanza::Presence::Status
- Defined in:
- lib/blather/stanza/presence/status.rb
Instance Method Summary collapse
-
#<=>(o) ⇒ true, false
Compare status based on priority and state: unavailable status is always less valuable than others Raises an error if the JIDs aren’t the same.
-
#available? ⇒ true, false
Check if the state is available.
-
#away? ⇒ true, false
Check if the state is away.
-
#chat? ⇒ true, false
Check if the state is chat.
-
#dnd? ⇒ true, false
Check if the state is dnd.
-
#message ⇒ String?
Get the status message.
-
#message=(message) ⇒ Object
Set the status message.
-
#priority ⇒ Fixnum<-128...127>
Get the priority of the status.
-
#priority=(new_priority) ⇒ Object
Set the priority of the status Ensures priority is between -128 and 127.
-
#state ⇒ <:available, :away, :chat, :dnd, :xa>
Get the state of the status.
-
#state=(state) ⇒ Object
Set the state Ensure state is one of :available, :away, :chat, :dnd, :xa or nil.
-
#xa? ⇒ true, false
Check if the state is xa.
Instance Method Details
#<=>(o) ⇒ true, false
Compare status based on priority and state: unavailable status is always less valuable than others Raises an error if the JIDs aren’t the same
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/blather/stanza/presence/status.rb', line 195 def <=>(o) if self.from || o.from unless self.from.stripped == o.from.stripped raise ArgumentError, "Cannot compare status from different JIDs: #{[self.from, o.from].inspect}" end end if (self.type.nil? && o.type.nil?) || (!self.type.nil? && !o.type.nil?) self.priority <=> o.priority elsif self.type.nil? && !o.type.nil? 1 elsif !self.type.nil? && o.type.nil? -1 end end |
#available? ⇒ true, false
Check if the state is available
102 103 104 |
# File 'lib/blather/stanza/presence/status.rb', line 102 def available? self.state == :available end |
#away? ⇒ true, false
Check if the state is away
109 110 111 |
# File 'lib/blather/stanza/presence/status.rb', line 109 def away? self.state == :away end |
#chat? ⇒ true, false
Check if the state is chat
116 117 118 |
# File 'lib/blather/stanza/presence/status.rb', line 116 def chat? self.state == :chat end |
#dnd? ⇒ true, false
Check if the state is dnd
123 124 125 |
# File 'lib/blather/stanza/presence/status.rb', line 123 def dnd? self.state == :dnd end |
#message ⇒ String?
Get the status message
178 179 180 |
# File 'lib/blather/stanza/presence/status.rb', line 178 def read_content :status end |
#message=(message) ⇒ Object
Set the status message
185 186 187 |
# File 'lib/blather/stanza/presence/status.rb', line 185 def () set_content_for :status, end |
#priority ⇒ Fixnum<-128...127>
Get the priority of the status
171 172 173 |
# File 'lib/blather/stanza/presence/status.rb', line 171 def priority read_content(:priority).to_i end |
#priority=(new_priority) ⇒ Object
Set the priority of the status Ensures priority is between -128 and 127
161 162 163 164 165 166 |
# File 'lib/blather/stanza/presence/status.rb', line 161 def priority=(new_priority) # :nodoc: if new_priority && !(-128..127).include?(new_priority.to_i) raise ArgumentError, 'Priority must be between -128 and +127' end set_content_for :priority, new_priority end |
#state ⇒ <:available, :away, :chat, :dnd, :xa>
Get the state of the status
151 152 153 154 155 |
# File 'lib/blather/stanza/presence/status.rb', line 151 def state state = type || content_from(:show) state = :available if state.blank? state.to_sym end |
#state=(state) ⇒ Object
Set the state Ensure state is one of :available, :away, :chat, :dnd, :xa or nil
138 139 140 141 142 143 144 145 146 |
# File 'lib/blather/stanza/presence/status.rb', line 138 def state=(state) # :nodoc: state = state.to_sym if state state = nil if state == :available if state && !VALID_STATES.include?(state) raise ArgumentError, "Invalid Status (#{state}), use: #{VALID_STATES*' '}" end set_content_for :show, state end |
#xa? ⇒ true, false
Check if the state is xa
130 131 132 |
# File 'lib/blather/stanza/presence/status.rb', line 130 def xa? self.state == :xa end |