adam 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +3 -3
- data/config/database.yml +1 -1
- data/lib/adam.rb +1 -1
- data/lib/adam/kill.rb +72 -11
- data/lib/adam/kill_log.rb +17 -9
- data/lib/adam/kill_log/validation_error.rb +1 -1
- data/lib/adam/killboard.rb +2 -2
- data/lib/adam/killboard/feed_error.rb +1 -1
- data/lib/adam/killmail.rb +17 -13
- data/lib/adam/killmail/validation_error.rb +1 -1
- data/lib/models.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -8,9 +8,9 @@ Adam is a library for all things [EVE](http://www.eveonline.com/).
|
|
8
8
|
|
9
9
|
## Features
|
10
10
|
|
11
|
-
*
|
12
|
-
*
|
13
|
-
* EDK-compatible
|
11
|
+
* Parses killmails
|
12
|
+
* Parses kill logs
|
13
|
+
* Imports killmails from EDK-compatible feeds
|
14
14
|
|
15
15
|
## Synopsis
|
16
16
|
|
data/config/database.yml
CHANGED
data/lib/adam.rb
CHANGED
data/lib/adam/kill.rb
CHANGED
@@ -2,6 +2,16 @@ require 'digest'
|
|
2
2
|
|
3
3
|
module Adam
|
4
4
|
|
5
|
+
# Instances of the Kill class represent a kill in the EVE Online universe.
|
6
|
+
#
|
7
|
+
# Accessors:
|
8
|
+
# * +eve_id+ - The EVE ID of the killmail. This is only populated if the kill was derived from a kill log.
|
9
|
+
# * +time+ - A time object set to the time of the kill.
|
10
|
+
# * +solar_system+ - A solar system object (see the SolarSystem class).
|
11
|
+
# * +victim+ - A victim object (see the Victim class).
|
12
|
+
# * +solar_system+ - A solar system object (see the SolarSystem class).
|
13
|
+
# * +involved_parties+ - An array of involved party objects (see the InvolvedParty class).
|
14
|
+
# * +loot+ - An array of loot objects (see the Loot class).
|
5
15
|
class Kill
|
6
16
|
attr_accessor :eve_id, :time, :solar_system, :victim, :involved_parties, :loot
|
7
17
|
|
@@ -9,6 +19,8 @@ module Adam
|
|
9
19
|
yield self if block_given?
|
10
20
|
end
|
11
21
|
|
22
|
+
# Reverse-engineer the killmail. This is particularly useful if it
|
23
|
+
# was originally derived from a kill log.
|
12
24
|
def to_killmail
|
13
25
|
|
14
26
|
killmail = ""
|
@@ -17,9 +29,9 @@ module Adam
|
|
17
29
|
killmail << "Victim: #{victim.pilot}\n"
|
18
30
|
killmail << "Corp: #{victim.corporation}\n"
|
19
31
|
killmail << "Alliance: #{victim.alliance}\n" if victim.alliance
|
20
|
-
killmail << "Alliance: Unknown\n"
|
32
|
+
killmail << "Alliance: Unknown\n" if victim.alliance.nil?
|
21
33
|
killmail << "Faction: #{victim.faction}\n" if victim.faction
|
22
|
-
killmail << "Faction: NONE\n"
|
34
|
+
killmail << "Faction: NONE\n" if victim.faction.nil?
|
23
35
|
killmail << "Destroyed: #{victim.ship}\n"
|
24
36
|
killmail << "System: #{solar_system.name}\n"
|
25
37
|
killmail << "Security: #{solar_system.security_status.round(2)}\n"
|
@@ -38,9 +50,9 @@ module Adam
|
|
38
50
|
killmail << "Security: #{involved_party.security_status.round(2)}\n"
|
39
51
|
killmail << "Corp: #{involved_party.corporation}\n"
|
40
52
|
killmail << "Alliance: #{involved_party.alliance}\n" if involved_party.alliance
|
41
|
-
killmail << "Alliance: NONE\n"
|
53
|
+
killmail << "Alliance: NONE\n" if involved_party.alliance.nil?
|
42
54
|
killmail << "Faction: #{involved_party.faction}\n" if involved_party.faction
|
43
|
-
killmail << "Faction: NONE\n"
|
55
|
+
killmail << "Faction: NONE\n" if involved_party.faction.nil?
|
44
56
|
killmail << "Ship: #{involved_party.ship}\n"
|
45
57
|
killmail << "Weapon: #{involved_party.weapon}\n"
|
46
58
|
killmail << "Damage Done: #{involved_party.damage_done}\n"
|
@@ -66,7 +78,7 @@ module Adam
|
|
66
78
|
destroyed_items.each do |loot|
|
67
79
|
killmail << "#{loot.name}"
|
68
80
|
killmail << ", Qty: #{loot.quantity}" if loot.quantity > 1
|
69
|
-
killmail << " (Cargo)" if loot.
|
81
|
+
killmail << " (Cargo)" if loot.cargo_hold
|
70
82
|
killmail << " (Drone Bay)" if loot.drone_bay
|
71
83
|
killmail << "\n"
|
72
84
|
end
|
@@ -80,7 +92,7 @@ module Adam
|
|
80
92
|
dropped_items.each do |loot|
|
81
93
|
killmail << "#{loot.name}"
|
82
94
|
killmail << ", Qty: #{loot.quantity}" if loot.quantity > 1
|
83
|
-
killmail << " (Cargo)" if loot.
|
95
|
+
killmail << " (Cargo)" if loot.cargo_hold
|
84
96
|
killmail << " (Drone Bay)" if loot.drone_bay
|
85
97
|
killmail << "\n"
|
86
98
|
end
|
@@ -91,6 +103,7 @@ module Adam
|
|
91
103
|
|
92
104
|
alias_method :to_s, :to_killmail
|
93
105
|
|
106
|
+
# Calculates the message digest of the killmail.
|
94
107
|
def digest
|
95
108
|
string = "#{time}#{victim.pilot}#{victim.ship}#{solar_system.name}#{victim.damage_taken}"
|
96
109
|
involved_parties.sort! { |x, y| x.damage_done <=> y.damage_done }
|
@@ -100,39 +113,87 @@ module Adam
|
|
100
113
|
|
101
114
|
end
|
102
115
|
|
116
|
+
# Instances of the SolarSystem class represent a solar system in the EVE universe.
|
117
|
+
#
|
118
|
+
# Accessors:
|
119
|
+
# * +name+ - A string describing the name of the solar system.
|
120
|
+
# * +security_status+ - A floating-point number describing the security status of the solar system.
|
103
121
|
class Kill::SolarSystem
|
104
122
|
attr_accessor :name, :security_status
|
105
123
|
|
106
124
|
def initialize
|
107
125
|
yield self if block_given?
|
108
126
|
end
|
109
|
-
|
110
127
|
end
|
111
128
|
|
129
|
+
# Instances of the Kill class represent a victim of a kill.
|
130
|
+
#
|
131
|
+
# Accessors:
|
132
|
+
# * +pilot+ - A string describing the name of the pilot.
|
133
|
+
# * +corporation+ - A string describing the name of the corporation the pilot is enrolled in.
|
134
|
+
# * +alliance+ - A string describing the name of the alliance the corporation is a member of. May be +nil+ if the corporation is not in an alliance.
|
135
|
+
# * +faction+ - A string describing the name of the faction the pilot is involved in. May be +nil+ if the pilot is not in a faction.
|
136
|
+
# * +ship+ - A string describing the name of the ship that was destroyed.
|
137
|
+
# * +damage_taken+ - An integer describing damage taken.
|
112
138
|
class Kill::Victim
|
113
139
|
attr_accessor :pilot, :corporation, :alliance, :faction, :ship, :damage_taken
|
114
140
|
|
115
141
|
def initialize
|
116
142
|
yield self if block_given?
|
117
143
|
end
|
118
|
-
|
119
144
|
end
|
120
145
|
|
146
|
+
# Instances of the InvolvedParty class represent an involved party in a kill.
|
147
|
+
#
|
148
|
+
# Accessors:
|
149
|
+
# * +type+ - A symbol describing whether the pilot was player-controlled (:PC) or non-player controlled (:NPC).
|
150
|
+
# * +pilot+ - A string describing the name of the pilot. For NPCs, this is +nil+.
|
151
|
+
# * +security_status+ - A floating-point number describing the security status of the pilot. For NPCs, this is +nil+.
|
152
|
+
# * +corporation+ - A string describing the name of the corporation the pilot is enrolled in. For NPCs, this may be nil.
|
153
|
+
# * +alliance+ - A string describing the name of the alliance the corporation is a member of. May be +nil+ if the corporation is not in an alliance.
|
154
|
+
# * +faction+ - A string describing the name of the faction the pilot is involved in. May be +nil+ if the pilot is not in a faction.
|
155
|
+
# * +ship+ - A string describing the name of the ship that the pilot was flying.
|
156
|
+
# * +weapon+ - A string describing the name of the weapon that was last fired by this pilot.
|
157
|
+
# * +damage_done+ - An integer describing damage done by this pilot.
|
158
|
+
# * +final_blow+ - A boolean describing whether or not this pilot made the final blow.
|
121
159
|
class Kill::InvolvedParty
|
122
160
|
attr_accessor :type, :pilot, :security_status, :corporation, :alliance, :faction, :ship, :weapon, :damage_done, :final_blow
|
123
161
|
|
162
|
+
def pc?
|
163
|
+
type == :PC
|
164
|
+
end
|
165
|
+
|
166
|
+
def npc?
|
167
|
+
type == :NPC
|
168
|
+
end
|
169
|
+
|
124
170
|
def initialize
|
125
171
|
yield self if block_given?
|
126
172
|
end
|
127
|
-
|
128
173
|
end
|
129
174
|
|
175
|
+
# Instances of the Loot class represent a piece of loot of a kill.
|
176
|
+
#
|
177
|
+
# Accessors:
|
178
|
+
# * +name+ - A string describing the name of the item.
|
179
|
+
# * +quantity+ - An integer describing the quantity of the item.
|
180
|
+
# * +cargo_hold+ - A boolean describing whether or not this item was in the cargo hold.
|
181
|
+
# * +drone_bay+ - A boolean describing whether or not this item was in the drone bay.
|
182
|
+
# * +dropped+ - A boolean describing whether or not this item was dropped.
|
130
183
|
class Kill::Loot
|
131
|
-
attr_accessor :name, :quantity, :
|
184
|
+
attr_accessor :name, :quantity, :cargo_hold, :drone_bay, :dropped
|
185
|
+
|
186
|
+
def cargo_hold?
|
187
|
+
cargo_hold
|
188
|
+
end
|
189
|
+
|
190
|
+
def dropped?
|
191
|
+
dropped
|
192
|
+
end
|
132
193
|
|
133
194
|
def initialize
|
134
195
|
yield self if block_given?
|
135
196
|
end
|
136
197
|
end
|
137
198
|
|
138
|
-
end
|
199
|
+
end
|
data/lib/adam/kill_log.rb
CHANGED
@@ -9,7 +9,11 @@ module Adam
|
|
9
9
|
module KillLog
|
10
10
|
|
11
11
|
extend self
|
12
|
-
|
12
|
+
|
13
|
+
# Parses a kill log and returns an array of Kill objects.
|
14
|
+
#
|
15
|
+
# Parameters:
|
16
|
+
# * +source+ - A kill log as returned by the EVE Online API.
|
13
17
|
def parse(source)
|
14
18
|
document = Hpricot.XML(source)
|
15
19
|
|
@@ -27,6 +31,10 @@ module Adam
|
|
27
31
|
|
28
32
|
private
|
29
33
|
|
34
|
+
# Parses a single element of a kill log.
|
35
|
+
#
|
36
|
+
# Parameters:
|
37
|
+
# * +kill_element+ - A single kill element.
|
30
38
|
def parse_single(kill_element)
|
31
39
|
|
32
40
|
Adam::Kill.new do |k|
|
@@ -48,8 +56,8 @@ module Adam
|
|
48
56
|
|
49
57
|
v.pilot = victim_element['characterName']
|
50
58
|
v.corporation = victim_element['corporatioNname']
|
51
|
-
v.alliance = victim_element['allianceName'] == '' ?
|
52
|
-
v.faction = victim_element['factionName'] == '' ?
|
59
|
+
v.alliance = victim_element['allianceName'] == '' ? nil : victim_element['allianceName']
|
60
|
+
v.faction = victim_element['factionName'] == '' ? nil: victim_element['factionName']
|
53
61
|
v.ship = Item.find(victim_element['shipTypeID']).name
|
54
62
|
v.damage_taken = victim_element['damageTaken'].to_i
|
55
63
|
end
|
@@ -62,11 +70,11 @@ module Adam
|
|
62
70
|
raise ValidationError, "Involved party corporation no longer exists" if involved_party_element['corporationName'].empty?
|
63
71
|
raise ValidationError, "Involved party alliance no longer exists" if involved_party_element['allianceName'].empty?
|
64
72
|
|
65
|
-
ip.type = involved_party_element['characterName'].empty? ?
|
73
|
+
ip.type = involved_party_element['characterName'].empty? ? :NPC : :PC
|
66
74
|
ip.pilot = involved_party_element['characterName'] unless involved_party_element['characterName'].empty?
|
67
75
|
ip.corporation = involved_party_element['corporationName']
|
68
|
-
ip.alliance = involved_party_element['allianceName'] == '' ?
|
69
|
-
ip.faction = involved_party_element['factionName'] == '' ?
|
76
|
+
ip.alliance = involved_party_element['allianceName'] == '' ? nil : involved_party_element['allianceName']
|
77
|
+
ip.faction = involved_party_element['factionName'] == '' ? nil : involved_party_element['factionName']
|
70
78
|
ip.security_status = involved_party_element['securityStatus'].to_f
|
71
79
|
ip.ship = Item.find(involved_party_element['shipTypeID']).name
|
72
80
|
ip.weapon = Item.find(involved_party_element['weaponTypeID']).name
|
@@ -82,7 +90,7 @@ module Adam
|
|
82
90
|
k.loot << Adam::Kill::Loot.new do |l|
|
83
91
|
l.name = Item.find(loot_element['typeID']).name
|
84
92
|
l.quantity = loot_element['qtyDropped'].to_i
|
85
|
-
l.
|
93
|
+
l.cargo_hold = loot_element['flag'] == '5' ? true : false
|
86
94
|
l.drone_bay = loot_element['flag'] == '87' ? true : false
|
87
95
|
l.dropped = true
|
88
96
|
end
|
@@ -92,7 +100,7 @@ module Adam
|
|
92
100
|
k.loot << Adam::Kill::Loot.new do |l|
|
93
101
|
l.name = Item.find(loot_element['typeID']).name
|
94
102
|
l.quantity = loot_element['qtyDestroyed'].to_i
|
95
|
-
l.
|
103
|
+
l.cargo_hold = loot_element['flag'] == '5' ? true : false
|
96
104
|
l.drone_bay = loot_element['flag'] == '87' ? true : false
|
97
105
|
l.dropped = false
|
98
106
|
end
|
@@ -105,4 +113,4 @@ module Adam
|
|
105
113
|
|
106
114
|
end
|
107
115
|
|
108
|
-
end
|
116
|
+
end
|
data/lib/adam/killboard.rb
CHANGED
@@ -15,7 +15,7 @@ module Adam
|
|
15
15
|
@uri, @feed_uri = options[:uri], options[:feed_uri]
|
16
16
|
end
|
17
17
|
|
18
|
-
#
|
18
|
+
# Parses an EDK-compatible feed and returns an array of killmail strings.
|
19
19
|
#
|
20
20
|
# +options+ is a hash with these keys:
|
21
21
|
# * +week+ - An integer determining which week to import. Defaults to current week.
|
@@ -49,4 +49,4 @@ module Adam
|
|
49
49
|
|
50
50
|
end
|
51
51
|
|
52
|
-
end
|
52
|
+
end
|
data/lib/adam/killmail.rb
CHANGED
@@ -9,6 +9,10 @@ module Adam
|
|
9
9
|
|
10
10
|
extend self
|
11
11
|
|
12
|
+
# Parses killmails and populates corresponding Kill objects.
|
13
|
+
#
|
14
|
+
# Parameters:
|
15
|
+
# * +source+ - A string containing the killmail to parse.
|
12
16
|
def parse(source)
|
13
17
|
raise ValidationError.new(source), "Killmail is empty" if source.empty?
|
14
18
|
|
@@ -40,9 +44,9 @@ module Adam
|
|
40
44
|
# Set pilot to nil if it's a moon
|
41
45
|
v.pilot = nil if v.pilot =~ /[a-zA-Z0-9\- ]+ - Moon [0-9]+/
|
42
46
|
|
43
|
-
# Convert alliance/faction from "unknown" or "none" to
|
44
|
-
v.alliance =
|
45
|
-
v.faction =
|
47
|
+
# Convert alliance/faction from "unknown" or "none" to nil
|
48
|
+
v.alliance = nil if v.alliance =~ /unknown|none/i
|
49
|
+
v.faction = nil if v.faction =~ /unknown|none/i
|
46
50
|
end
|
47
51
|
|
48
52
|
raise ValidationError.new(source), "No faction called '#{kill.victim.faction}' exists" if kill.victim.faction and !Faction.exists? :name => kill.victim.faction
|
@@ -60,7 +64,7 @@ module Adam
|
|
60
64
|
|
61
65
|
when 8
|
62
66
|
involved_party = Adam::Kill::InvolvedParty.new do |ip|
|
63
|
-
ip.type =
|
67
|
+
ip.type = :PC
|
64
68
|
ip.pilot = snippet[/Name: ([a-zA-Z0-9]{1}[a-zA-Z0-9'. -]{1,48}[a-zA-Z0-9.]{1})/, 1] or raise ValidationError.new(source), "Involved party #{i+1} pilot malformed"
|
65
69
|
ip.security_status = snippet[/Security: ([\-\.0-9]+)/, 1].to_f or raise ValidationError.new(source), "Involved party #{i+1} security malformed"
|
66
70
|
ip.corporation = snippet[/Corp: ([a-zA-Z0-9]{1}[a-zA-Z0-9'. -]{1,48}[a-zA-Z0-9.]{1})/, 1] or raise ValidationError.new(source), "Involved party #{i+1} corporation malformed"
|
@@ -71,14 +75,14 @@ module Adam
|
|
71
75
|
ip.damage_done = (snippet[/Damage Done: ([0-9]+)/, 1] or raise ValidationError.new(source), "Involved party #{i+1} damage malformed").to_i
|
72
76
|
ip.final_blow = snippet =~ /\(laid the final blow\)/ ? true : false
|
73
77
|
|
74
|
-
# Convert alliance/faction from "unknown" or "none" to
|
75
|
-
ip.alliance =
|
76
|
-
ip.faction =
|
78
|
+
# Convert alliance/faction from "unknown" or "none" to nil
|
79
|
+
ip.alliance = nil if ip.alliance =~ /unknown|none/i
|
80
|
+
ip.faction = nil if ip.faction =~ /unknown|none/i
|
77
81
|
end
|
78
82
|
|
79
83
|
when 2
|
80
84
|
involved_party = Adam::Kill::InvolvedParty.new do |ip|
|
81
|
-
ip.type =
|
85
|
+
ip.type = :NPC
|
82
86
|
ip.ship = snippet[/Name: ([a-zA-Z0-9]{1}[a-zA-Z0-9'. -]{1,48}[a-zA-Z0-9.]{1})/, 1] or raise ValidationError.new(source), "Involved party #{i+1} ship malformed"
|
83
87
|
ip.damage_done = (snippet[/Damage Done: ([0-9]+)/, 1] or raise ValidationError.new(source), "Involved party #{i+1} damage malformed").to_i
|
84
88
|
ip.final_blow = snippet =~ /\(laid the final blow\)/ ? true : false
|
@@ -110,11 +114,11 @@ module Adam
|
|
110
114
|
loot = Adam::Kill::Loot.new do |l|
|
111
115
|
l.name = snippet[/([^,\(\)]+)/, 1] or raise ValidationError.new(source), "Destroyed item #{i+1} name malformed"
|
112
116
|
l.quantity = snippet =~ /Qty: ([0-9]+)/ ? snippet[/Qty: ([0-9]+)/, 1].to_i : 1
|
113
|
-
l.
|
117
|
+
l.cargo_hold = snippet[/(Cargo)/] ? true : false
|
114
118
|
l.drone_bay = snippet[/(Drone Bay)/] ? true : false
|
115
119
|
l.dropped = false
|
116
120
|
end
|
117
|
-
existing_loot = kill.loot.select { |el| el.name.eql?(loot.name) and el.
|
121
|
+
existing_loot = kill.loot.select { |el| el.name.eql?(loot.name) and el.cargo_hold.eql?(loot.cargo_hold) and el.drone_bay.eql?(loot.drone_bay) and el.dropped.eql?(loot.dropped) }[0]
|
118
122
|
existing_loot ? existing_loot.quantity += loot.quantity : kill.loot << loot
|
119
123
|
end
|
120
124
|
end
|
@@ -124,11 +128,11 @@ module Adam
|
|
124
128
|
loot = Adam::Kill::Loot.new do |l|
|
125
129
|
l.name = snippet[/([^,\(\)]+)/, 1] or raise ValidationError.new(source), "Dropped item #{i+1} name malformed"
|
126
130
|
l.quantity = snippet =~ /Qty: ([0-9]+)/ ? snippet[/Qty: ([0-9]+)/, 1].to_i : 1
|
127
|
-
l.
|
131
|
+
l.cargo_hold = snippet[/(Cargo)/] ? true : false
|
128
132
|
l.drone_bay = snippet[/(Drone Bay)/] ? true : false
|
129
133
|
l.dropped = true
|
130
134
|
end
|
131
|
-
existing_loot = kill.loot.select { |el| el.name.eql?(loot.name) and el.
|
135
|
+
existing_loot = kill.loot.select { |el| el.name.eql?(loot.name) and el.cargo_hold.eql?(loot.cargo_hold) and el.drone_bay.eql?(loot.drone_bay) and el.dropped.eql?(loot.dropped) }[0]
|
132
136
|
existing_loot ? existing_loot.quantity += loot.quantity : kill.loot << loot
|
133
137
|
end
|
134
138
|
end
|
@@ -139,4 +143,4 @@ module Adam
|
|
139
143
|
|
140
144
|
end
|
141
145
|
|
142
|
-
end
|
146
|
+
end
|
data/lib/models.rb
CHANGED