Class: NerdLog::Fight
- Inherits:
-
Object
- Object
- NerdLog::Fight
- Defined in:
- lib/nerd_log/fight.rb
Instance Attribute Summary collapse
-
#http_connection ⇒ Object
readonly
Returns the value of attribute http_connection.
-
#report_id ⇒ Object
readonly
Returns the value of attribute report_id.
Instance Method Summary collapse
- #fetch ⇒ Object
- #fights ⇒ Object
-
#initialize(options = {}) ⇒ Fight
constructor
A new instance of Fight.
Constructor Details
#initialize(options = {}) ⇒ Fight
Returns a new instance of Fight.
6 7 8 9 |
# File 'lib/nerd_log/fight.rb', line 6 def initialize( = {}) @report_id = .fetch(:report_id) @http_connection = .fetch(:http_connection, NerdLog.configuration.http_connection) end |
Instance Attribute Details
#http_connection ⇒ Object (readonly)
Returns the value of attribute http_connection.
5 6 7 |
# File 'lib/nerd_log/fight.rb', line 5 def http_connection @http_connection end |
#report_id ⇒ Object (readonly)
Returns the value of attribute report_id.
5 6 7 |
# File 'lib/nerd_log/fight.rb', line 5 def report_id @report_id end |
Instance Method Details
#fetch ⇒ Object
34 35 36 37 38 |
# File 'lib/nerd_log/fight.rb', line 34 def fetch response = http_connection.get("report/fights/#{report_id}") response end |
#fights ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 |