Class: Wowr::Classes::Character

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

Overview

See Also: Guild

Direct Known Subclasses

FullCharacter, SearchCharacter

Constant Summary collapse

@@race_icon_url_base =
'images/icons/race/'
@@class_icon_url_base =
'images/icons/class/'
@@portrait_url_base =
'images/portraits/'
@@icon_types =
{:default => 'wow-default', 70 => 'wow-70', :other => 'wow'}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elem, api = nil) ⇒ Character

Returns a new instance of Character.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/wowr/character.rb', line 38

def initialize(elem, api = nil)
	@api = api
	
	@name	 			= elem[:name]
	@level 			= elem[:level].to_i
	@url 				= elem[:url] || elem[:charUrl]
	@rank 			= elem[:rank].to_i
	
	@klass 			= elem[:class]
	@klass_id		= elem[:classId].to_i
	
	@gender 		= elem[:gender]
	@gender_id 	= elem[:genderId].to_i
	
	@race 			= elem[:race]
	@race_id 		= elem[:raceId].to_i
	
	@guild			= elem[:guild] == "" ? nil : elem[:guild]
	@guild_id		= elem[:guildId].to_i == 0 ? nil : elem[:guildId].to_i
	@guild_url	= elem[:guildUrl] == "" ? nil : elem[:guildUrl]
	
	@realm			= elem[:realm] == "" ? nil : elem[:realm]
	
	@battle_group 		= elem[:battleGroup] == "" ? nil : elem[:battleGroup]
	@battle_group_id 	= elem[:battleGroupId].to_i
	
	@relevance 		= elem[:relevance].to_i
	@search_rank 	= elem[:searchRank].to_i
	
	# Incoming string is 2007-02-24 20:33:04.0, parse to datetime
	#@last_login 	= elem[:lastLoginDate] == "" ? nil : DateTime.parse(elem[:lastLoginDate])
	@last_login 	= elem[:lastLoginDate] == "" ? nil : elem[:lastLoginDate]
	
	# From ArenaTeam info, can be blank on normal requests
	#<character battleGroup="" charUrl="r=Draenor&amp;n=Lothaar" class="Paladin" classId="2"
	# contribution="1602" gamesPlayed="10" gamesWon="7" gender="Male" genderId="0"
	# guild="Passion" guildId="36659" guildUrl="r=Draenor&amp;n=Passion&amp;p=1" name="Lothaar"
	# race="Human" raceId="1" seasonGamesPlayed="20" seasonGamesWon="13" teamRank="1"/>
	@season_games_played 	= elem[:seasonGamesPlayed] == "" ? nil : elem[:seasonGamesPlayed].to_i
	@season_games_won 		= elem[:seasonGamesWon] == "" ? nil : elem[:seasonGamesWon].to_i
	@team_rank 						= elem[:teamRank] == "" ? nil : elem[:teamRank].to_i
	@contribution					= elem[:contribution] == "" ? nil : elem[:contribution].to_i
	#@char_url 						= elem[:charUrl]	# TODO: Merge with URL?
end

Instance Attribute Details

#battle_groupObject (readonly)

Returns the value of attribute battle_group.



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

def battle_group
  @battle_group
end

#contributionObject (readonly)

Returns the value of attribute contribution.



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

def contribution
  @contribution
end

#genderObject (readonly)

Returns the value of attribute gender.



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

def gender
  @gender
end

#gender_idObject (readonly)

Returns the value of attribute gender_id.



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

def gender_id
  @gender_id
end

#guildObject (readonly)

Returns the value of attribute guild.



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

def guild
  @guild
end

#guild_idObject (readonly)

Returns the value of attribute guild_id.



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

def guild_id
  @guild_id
end

#guild_urlObject (readonly)

Returns the value of attribute guild_url.



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

def guild_url
  @guild_url
end

#klassObject (readonly)

Returns the value of attribute klass.



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

def klass
  @klass
end

#klass_idObject (readonly)

Returns the value of attribute klass_id.



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

def klass_id
  @klass_id
end

#last_loginObject (readonly)

Returns the value of attribute last_login.



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

def 
  @last_login
end

#levelObject (readonly) Also known as: to_i

Returns the value of attribute level.



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

def level
  @level
end

#nameObject (readonly) Also known as: to_s

Returns the value of attribute name.



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

def name
  @name
end

#raceObject (readonly)

Returns the value of attribute race.



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

def race
  @race
end

#race_idObject (readonly)

Returns the value of attribute race_id.



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

def race_id
  @race_id
end

#rankObject (readonly)

Returns the value of attribute rank.



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

def rank
  @rank
end

#realmObject (readonly)

Returns the value of attribute realm.



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

def realm
  @realm
end

#relevanceObject (readonly)

Returns the value of attribute relevance.



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

def relevance
  @relevance
end

#search_rankObject (readonly)

Returns the value of attribute search_rank.



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

def search_rank
  @search_rank
end

#season_games_playedObject (readonly)

Returns the value of attribute season_games_played.



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

def season_games_played
  @season_games_played
end

#season_games_wonObject (readonly)

Returns the value of attribute season_games_won.



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

def season_games_won
  @season_games_won
end

#team_rankObject (readonly)

Returns the value of attribute team_rank.



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

def team_rank
  @team_rank
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#class_iconObject



108
109
110
111
# File 'lib/wowr/character.rb', line 108

def class_icon
	# http://armory.worldofwarcraft.com/images/icons/class/8.gif
	return base + @@class_icon_url_base + "#{@klass_id.to_s}.gif"
end

#icon(type = nil) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/wowr/character.rb', line 84

def icon(type = nil)
	if !type.nil? && !@@icon_types.include?(type)
		raise Wowr::Exceptions::InvalidIconType.new(@@icon_types)
	end
	
	if (type.nil?) && (@level == 70)
		dir = @@icon_types[70]
	elsif (type.nil?)
		dir = @@icon_types[:other]
	else
		dir = @@icon_types[type]
	end
	
	# http://armory.worldofwarcraft.com/images/portraits/wow-70/1-7-8.gif
	return base + @@portrait_url_base + dir + "/#{@gender_id}-#{@race_id}-#{@klass_id}.gif"
end

#race_iconObject



102
103
104
105
# File 'lib/wowr/character.rb', line 102

def race_icon
	# http://armory.worldofwarcraft.com/images/icons/race/11-1.gif
	return base + @@race_icon_url_base + "#{@race_id}-#{@gender_id.to_s}.gif"
end