Class: Wot::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/wot/player.rb,
lib/wot/player/info.rb,
lib/wot/player/tank.rb,
lib/wot/player/statistics.rb,
lib/wot/player/achievement.rb,
lib/wot/player/extended_statistics.rb

Defined Under Namespace

Classes: Achievement, ExtendedStatistics, Info, Statistics, Tank

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, api) ⇒ Player

Returns a new instance of Player.



35
36
37
38
39
40
# File 'lib/wot/player.rb', line 35

def initialize(options, api)
  @api = api
  @id = options[:account_id]
  @account_id = @id
  @nickname = options[:nickname]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)



59
60
61
62
# File 'lib/wot/player.rb', line 59

def method_missing(method_name, *args, &block)
  info
  return @info.send method_name
end

Instance Attribute Details

#account_idObject

Returns the value of attribute account_id.



8
9
10
# File 'lib/wot/player.rb', line 8

def 
  @account_id
end

#apiObject

Returns the value of attribute api.



8
9
10
# File 'lib/wot/player.rb', line 8

def api
  @api
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/wot/player.rb', line 8

def id
  @id
end

#nicknameObject

Returns the value of attribute nickname.



8
9
10
# File 'lib/wot/player.rb', line 8

def nickname
  @nickname
end

Class Method Details

.create_players_from_data(data, api) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/wot/player.rb', line 27

def self.create_players_from_data(data,api)
  players = []
  data.each do |item|
    players << Wot::Player.new(item, api)
  end
  return players
end

.find(api, account_ids, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/wot/player.rb', line 17

def self.find(api, , options = {})
  parameters = {
    account_id: (.class == Array ?  : []),
    fields: 'account_id,nickname'
  }
  parameters = parameters.merge options
  response = api.make_request 'account/info/', parameters
  return create_players_from_data response[:data].values, api
end

.search(api, nickname, options = {}) ⇒ Object



10
11
12
13
14
15
# File 'lib/wot/player.rb', line 10

def self.search(api, nickname, options = {})
  parameters = {search: nickname}
  parameters = parameters.merge options
  response = api.make_request 'account/list/', parameters
  return create_players_from_data response[:data], api
end

Instance Method Details

#achievementsObject



47
48
49
50
# File 'lib/wot/player.rb', line 47

def achievements
  @achievements ||= Wot::Player::Achievement.get_achievements(self,@api)
  return @achievements
end

#infoObject



52
53
54
55
# File 'lib/wot/player.rb', line 52

def info
  @info ||= Wot::Player::Info.new(self, @api)
  return @info
end

#tanksObject



42
43
44
45
# File 'lib/wot/player.rb', line 42

def tanks
  @tanks ||= Wot::Player::Tank.get_tanks(self,@api)
  return @tanks
end