class NerdLog::Fight
Attributes
http_connection[R]
report_id[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/nerd_log/fight.rb, line 6 def initialize(options = {}) @report_id = options.fetch(:report_id) @http_connection = options.fetch(:http_connection, NerdLog.configuration.http_connection) end
Public Instance Methods
fetch()
click to toggle source
# File lib/nerd_log/fight.rb, line 34 def fetch response = http_connection.get("report/fights/#{report_id}") response end
fights()
click to toggle source
# File lib/nerd_log/fight.rb, line 11 def fights unless @fights body = fetch.body raw_fights = body['fights'].select {|f| f['boss'] != 0} friendlies = body['friendlies'].select {|f| f['type'] != 'NPC'} @fights = {} raw_fights.each do |raw_fight| @fights[raw_fight['id']] = OpenStruct.new(id: raw_fight['boss'], kill: raw_fight['kill'], difficulty: raw_fight['difficulty'], players: []) end friendlies.each do |player| player['fights'].each do |fight| boss_fight = @fights[fight['id']] boss_fight.players.push(player['name']) if boss_fight end end end @fights.values end