Class: Bf3::Player

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

Instance Method Summary collapse

Constructor Details

#initialize(name, platform) ⇒ Player

Returns a new instance of Player.



9
10
11
12
# File 'lib/bf3.rb', line 9

def initialize(name, platform)
  @name = name
  @platform = platform
end

Instance Method Details

#callUp(opt = 'clear,global') ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bf3.rb', line 14

def callUp(opt='clear,global')
  body = {
    player: @name,
    output: 'json',
    opt: opt
  }
  response = HTTParty.post("http://api.bf3stats.com/#{@platform}/player/", :body => body)
  if response.code == 200
    stats = JSON(response.body)['stats']
    @stats = stats
    return stats
  else
    return response
  end
end

#kdrObject



30
31
32
33
# File 'lib/bf3.rb', line 30

def kdr
  self.callUp() unless @stats and @stats['global']['kills']
  return @stats['global']['kills'].to_f / @stats['global']['deaths']
end