Class: Elekk::Character
- Inherits:
-
Object
- Object
- Elekk::Character
- Defined in:
- lib/elekk/character.rb
Instance Attribute Summary collapse
- #armory ⇒ Object
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#realm ⇒ Object
readonly
Returns the value of attribute realm.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
Instance Method Summary collapse
- #achievements(category) ⇒ Object
- #faction ⇒ Object
- #feed ⇒ Object
- #fullname(tag = nil) ⇒ Object
- #gender ⇒ Object
-
#initialize(name, realm, opts = {}) ⇒ Character
constructor
A new instance of Character.
- #klass ⇒ Object
- #level ⇒ Object
- #points ⇒ Object
- #portrait ⇒ Object
- #race ⇒ Object
- #sheet ⇒ Object
- #spec(which) ⇒ Object
- #xml(resource, opts = {}) ⇒ Object
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
#armory ⇒ Object
15 16 17 |
# File 'lib/elekk/character.rb', line 15 def armory @armory ||= Armory.new @realm, :region => @region end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/elekk/character.rb', line 3 def name @name end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
5 6 7 |
# File 'lib/elekk/character.rb', line 5 def properties @properties end |
#realm ⇒ Object (readonly)
Returns the value of attribute realm.
3 4 5 |
# File 'lib/elekk/character.rb', line 3 def realm @realm end |
#region ⇒ Object (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 |
#faction ⇒ Object
40 41 42 |
# File 'lib/elekk/character.rb', line 40 def faction @properties[:faction] ||= Faction[sheet.at_css('character')['factionId'].to_i] end |
#feed ⇒ Object
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 |
#gender ⇒ Object
52 53 54 |
# File 'lib/elekk/character.rb', line 52 def gender @properties[:gender] ||= Gender[sheet.at_css('character')['genderId'].to_i] end |
#klass ⇒ Object
36 37 38 |
# File 'lib/elekk/character.rb', line 36 def klass @properties[:klass] ||= Klass[sheet.at_css('character')['classId'].to_i] end |
#level ⇒ Object
48 49 50 |
# File 'lib/elekk/character.rb', line 48 def level @properties[:level] ||= sheet.at_css('character')['level'].to_i end |
#points ⇒ Object
56 57 58 |
# File 'lib/elekk/character.rb', line 56 def points @properties[:points] ||= sheet.at_css('character')['points'].to_i end |
#portrait ⇒ Object
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 |
#race ⇒ Object
44 45 46 |
# File 'lib/elekk/character.rb', line 44 def race @properties[:race] ||= Race[sheet.at_css('character')['raceId'].to_i] end |
#sheet ⇒ Object
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 |