Class: Wot::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/wot-api/player.rb,
lib/wot-api/player/info.rb,
lib/wot-api/player/tank.rb,
lib/wot-api/player/statistics.rb,
lib/wot-api/player/achievement.rb,
lib/wot-api/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.



37
38
39
40
41
42
# File 'lib/wot-api/player.rb', line 37

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)



61
62
63
64
# File 'lib/wot-api/player.rb', line 61

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.



10
11
12
# File 'lib/wot-api/player.rb', line 10

def 
  @account_id
end

#apiObject

Returns the value of attribute api.



10
11
12
# File 'lib/wot-api/player.rb', line 10

def api
  @api
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/wot-api/player.rb', line 10

def id
  @id
end

#nicknameObject

Returns the value of attribute nickname.



10
11
12
# File 'lib/wot-api/player.rb', line 10

def nickname
  @nickname
end

Class Method Details

.create_players_from_data(data, api) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/wot-api/player.rb', line 29

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



19
20
21
22
23
24
25
26
27
# File 'lib/wot-api/player.rb', line 19

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



12
13
14
15
16
17
# File 'lib/wot-api/player.rb', line 12

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



49
50
51
52
# File 'lib/wot-api/player.rb', line 49

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

#infoObject



54
55
56
57
# File 'lib/wot-api/player.rb', line 54

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

#tanksObject



44
45
46
47
# File 'lib/wot-api/player.rb', line 44

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