Class: Warchat::Models::Character

Inherits:
Warchat::Model show all
Defined in:
lib/warchat/models/character.rb

Constant Summary collapse

CLASSES =
{1=>'Warrior',2=>'Paladin',3=>'Hunter',4=>'Rogue',5=>'Priest',6=>'Death Knight',7=>'Shaman',8=>'Mage',9=>'Warlock',11=>'Druid'}
RACES =
{1=>'Human',2=>'Orc',3=>'Dwarf',4=>'Night Elf',5=>'Forsaken',6=>'Tauren',7=>'Gnome',8=>'Troll',9=>'Goblin',10=>'Blood Elf',11=>'Draenei',22=>'Worgen'}

Instance Attribute Summary

Attributes inherited from Warchat::Model

#data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Warchat::Model

all, find, find_or_create, #id, mutex, #name, #realm, #update

Constructor Details

#initialize(data) ⇒ Character

Returns a new instance of Character.



13
14
15
16
# File 'lib/warchat/models/character.rb', line 13

def initialize data
  super
  @count = 0
end

Class Method Details

.onlineObject



8
9
10
# File 'lib/warchat/models/character.rb', line 8

def online
  all.select &:online?
end

Instance Method Details

#inspectObject



46
47
48
# File 'lib/warchat/models/character.rb', line 46

def inspect
  "<#{self.class.name} name:#{name.inspect} realm:#{realm.inspect} klass:#{klass.inspect} level:#{level.inspect} race:#{race.inspect}>"
end

#klassObject



26
27
28
# File 'lib/warchat/models/character.rb', line 26

def klass
  CLASSES[data['c']]
end

#levelObject



18
19
20
# File 'lib/warchat/models/character.rb', line 18

def level
  data['l']
end

#offlineObject



42
43
44
# File 'lib/warchat/models/character.rb', line 42

def offline
  @count -= 1
end

#onlineObject



38
39
40
# File 'lib/warchat/models/character.rb', line 38

def online
  @count += 1
end

#online?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/warchat/models/character.rb', line 34

def online?
  count > 0 
end

#raceObject



30
31
32
# File 'lib/warchat/models/character.rb', line 30

def race
  RACES[data['ra']]
end

#rankObject



22
23
24
# File 'lib/warchat/models/character.rb', line 22

def rank
  data['grank']
end