Class: Elekk::Character

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, realm, opts = {}) ⇒ Character

Returns a new instance of Character.



7
8
9
10
11
12
13
# File 'lib/elekk/character.rb', line 7

def initialize(name, realm, opts={})
  @name = name
  @realm = realm
  @region = opts[:region] || Elekk::default_region
  @armory = opts[:armory]
  @properties = { :name => @name, :realm => @realm, :region => @region }
end

Instance Attribute Details

#armoryObject



15
16
17
# File 'lib/elekk/character.rb', line 15

def armory
  @armory ||= Armory.new @realm, :region => @region
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/elekk/character.rb', line 3

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



5
6
7
# File 'lib/elekk/character.rb', line 5

def properties
  @properties
end

#realmObject (readonly)

Returns the value of attribute realm.



3
4
5
# File 'lib/elekk/character.rb', line 3

def realm
  @realm
end

#regionObject (readonly)

Returns the value of attribute region.



3
4
5
# File 'lib/elekk/character.rb', line 3

def region
  @region
end

Instance Method Details

#achievements(category) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/elekk/character.rb', line 23

def achievements(category)
  category = AchievementCategory[category]
  @achievements ||= {}
  @achievements[category.to_sym] ||=
    xml(:achievements, :c => category.to_i).css('achievement').map {|x| Achievement.from_xml x}
  
end

#factionObject



40
41
42
# File 'lib/elekk/character.rb', line 40

def faction
  @properties[:faction] ||= Faction[sheet.at_css('character')['factionId'].to_i]
end

#feedObject



60
61
62
# File 'lib/elekk/character.rb', line 60

def feed
  self.armory.get_feed @name, @realm
end

#fullname(tag = nil) ⇒ Object



85
86
87
88
89
# File 'lib/elekk/character.rb', line 85

def fullname(tag=nil)
  n = name
  n = "<#{tag}>#{n}</#{tag}>" if tag unless tag == ''
  sheet.at_css('character')['prefix'] + n + sheet.at_css('character')['suffix']
end

#genderObject



52
53
54
# File 'lib/elekk/character.rb', line 52

def gender
  @properties[:gender] ||= Gender[sheet.at_css('character')['genderId'].to_i]
end

#klassObject



36
37
38
# File 'lib/elekk/character.rb', line 36

def klass
  @properties[:klass] ||= Klass[sheet.at_css('character')['classId'].to_i]
end

#levelObject



48
49
50
# File 'lib/elekk/character.rb', line 48

def level
  @properties[:level] ||= sheet.at_css('character')['level'].to_i
end

#pointsObject



56
57
58
# File 'lib/elekk/character.rb', line 56

def points
  @properties[:points] ||= sheet.at_css('character')['points'].to_i
end

#portraitObject



78
79
80
81
82
83
# File 'lib/elekk/character.rb', line 78

def portrait
  type = 'default'
  [60, 70, 80].each { |m| type = m if level >= m }
  
  self.armory.url "_images/portraits/wow-#{type}/#{gender.id}-#{race.id}-#{klass.id}.gif"
end

#raceObject



44
45
46
# File 'lib/elekk/character.rb', line 44

def race
  @properties[:race] ||= Race[sheet.at_css('character')['raceId'].to_i]
end

#sheetObject



19
20
21
# File 'lib/elekk/character.rb', line 19

def sheet
  @sheet ||= xml :sheet
end

#spec(which) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/elekk/character.rb', line 64

def spec(which)
  if not @properties[:specs]
    specs = {}
    primary = 0
    sheet.css('talentSpecs talentSpec').each do |t|
      n = t['group'].to_i-1
      specs[n] = TalentTree.const_get(klass.to_sym)[t['prim'].to_s]
      specs[:active] = specs[n] if t['active']
    end
    @properties[:specs] = specs
  end
  @properties[:specs][which]
end

#xml(resource, opts = {}) ⇒ Object



31
32
33
34
# File 'lib/elekk/character.rb', line 31

def xml(resource, opts={})
  opts = {:r => @realm, :cn => @name}.merge opts
  self.armory.get_xml "character-#{resource}", opts
end