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

Parameters:

Returns:

  • (true, false)


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

Returns:

  • (true, false)


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

Returns:

  • (true, false)


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

Returns:

  • (true, false)


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

Returns:

  • (true, false)


123
124
125
# File 'lib/blather/stanza/presence/status.rb', line 123

def dnd?
  self.state == :dnd
end

#messageString?

Get the status message

Returns:

  • (String, nil)


178
179
180
# File 'lib/blather/stanza/presence/status.rb', line 178

def message
  read_content :status
end

#message=(message) ⇒ Object

Set the status message

Parameters:

  • message (String, nil)


185
186
187
# File 'lib/blather/stanza/presence/status.rb', line 185

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

#priorityFixnum<-128...127>

Get the priority of the status

Returns:

  • (Fixnum<-128...127>)


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

Parameters:

  • new_priority (Fixnum<-128...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

Returns:

  • (<:available, :away, :chat, :dnd, :xa>)


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

Parameters:

  • state (<:available, :away, :chat, :dnd, :xa, 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

Returns:

  • (true, false)


130
131
132
# File 'lib/blather/stanza/presence/status.rb', line 130

def xa?
  self.state == :xa
end