Module: Blather::Stanza::Presence::Status::InstanceMethods

Included in:
Blather::Stanza::Presence::Status
Defined in:
lib/blather/stanza/presence/status.rb

Instance Method Summary collapse

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



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/blather/stanza/presence/status.rb', line 199

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?)
    if self.priority == o.priority
      POSSIBLE_STATES.index(self.state) <=> POSSIBLE_STATES.index(o.state)
    else
      self.priority <=> o.priority
    end
  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



106
107
108
# File 'lib/blather/stanza/presence/status.rb', line 106

def available?
  self.state == :available
end

#away?true, false

Check if the state is away



113
114
115
# File 'lib/blather/stanza/presence/status.rb', line 113

def away?
  self.state == :away
end

#chat?true, false

Check if the state is chat



120
121
122
# File 'lib/blather/stanza/presence/status.rb', line 120

def chat?
  self.state == :chat
end

#dnd?true, false

Check if the state is dnd



127
128
129
# File 'lib/blather/stanza/presence/status.rb', line 127

def dnd?
  self.state == :dnd
end

#messageString?

Get the status message



182
183
184
# File 'lib/blather/stanza/presence/status.rb', line 182

def message
  read_content :status
end

#message=(message) ⇒ Object

Set the status message



189
190
191
# File 'lib/blather/stanza/presence/status.rb', line 189

def message=(message)
  set_content_for :status, message
end

#priorityFixnum<-128...127>

Get the priority of the status



175
176
177
# File 'lib/blather/stanza/presence/status.rb', line 175

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



165
166
167
168
169
170
# File 'lib/blather/stanza/presence/status.rb', line 165

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



155
156
157
158
159
# File 'lib/blather/stanza/presence/status.rb', line 155

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



142
143
144
145
146
147
148
149
150
# File 'lib/blather/stanza/presence/status.rb', line 142

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



134
135
136
# File 'lib/blather/stanza/presence/status.rb', line 134

def xa?
  self.state == :xa
end