Class: Armory::Character

Inherits:
Object
  • Object
show all
Defined in:
lib/armory/character.rb

Defined Under Namespace

Classes: Item

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCharacter

Returns a new instance of Character.



10
11
12
# File 'lib/armory/character.rb', line 10

def initialize
  @items = []
end

Instance Attribute Details

#battle_groupObject

Returns the value of attribute battle_group.



6
7
8
# File 'lib/armory/character.rb', line 6

def battle_group
  @battle_group
end

#class_idObject

Returns the value of attribute class_id.



7
8
9
# File 'lib/armory/character.rb', line 7

def class_id
  @class_id
end

#faction_idObject

Returns the value of attribute faction_id.



7
8
9
# File 'lib/armory/character.rb', line 7

def faction_id
  @faction_id
end

#gender_idObject

Returns the value of attribute gender_id.



7
8
9
# File 'lib/armory/character.rb', line 7

def gender_id
  @gender_id
end

#guildObject

Returns the value of attribute guild.



6
7
8
# File 'lib/armory/character.rb', line 6

def guild
  @guild
end

#itemsObject (readonly)

Returns the value of attribute items.



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

def items
  @items
end

#last_modifiedObject

Returns the value of attribute last_modified.



6
7
8
# File 'lib/armory/character.rb', line 6

def last_modified
  @last_modified
end

#levelObject

Returns the value of attribute level.



6
7
8
# File 'lib/armory/character.rb', line 6

def level
  @level
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/armory/character.rb', line 6

def name
  @name
end

#race_idObject

Returns the value of attribute race_id.



7
8
9
# File 'lib/armory/character.rb', line 7

def race_id
  @race_id
end

#realmObject

Returns the value of attribute realm.



6
7
8
# File 'lib/armory/character.rb', line 6

def realm
  @realm
end

Class Method Details

.from_armory(doc) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/armory/character.rb', line 30

def self.from_armory(doc)
  Character.new.tap do |char|
    info = doc.css("characterInfo character").first

    char.name  = info.attr("name")
    char.level = info.attr("level").to_i
    char.guild = info.attr("guildName")
    char.realm = info.attr("realm")
    char.battle_group  = info.attr("battleGroup")
    char.last_modified = Date.parse(info.attr('lastModified'))

    # Attribute ids
    char.race_id    = info.attr("raceId").to_i
    char.class_id   = info.attr("classId").to_i
    char.gender_id  = info.attr("genderId").to_i
    char.faction_id = info.attr("factionId").to_i

    doc.css("characterTab items item").each do |item|
      char.items << Item.from_armory(item)
    end
  end
end

Instance Method Details

#class_nameObject



14
15
16
# File 'lib/armory/character.rb', line 14

def class_name
  Armory::Classes[class_id]
end

#factionObject



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

def faction
  Armory::Factions[faction_id]
end

#genderObject



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

def gender
  Armory::Genders[gender_id]
end

#raceObject



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

def race
  Armory::Races[race_id]
end