-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpilot.rb
More file actions
69 lines (59 loc) · 1.97 KB
/
Copy pathpilot.rb
File metadata and controls
69 lines (59 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class Pilot < ActiveRecord::Base
belongs_to :kill
belongs_to :solar_system
belongs_to :alliance
validates_presence_of :name, :corporation_name, :security_status
validates_presence_of :damage
## accessors
#
def ship_name=( ship_name )
ship = InvType.find_by_name( ship_name )
self.ship_id = ship.nil? ? 0 : ship.id
end
def system_name=( system_name )
solar_system = SolarSystem.find_by_name( system_name )
self.solar_system_id = solar_system.nil? ? 0 : solar_system.id
end
def alliance_name=( alliance_name )
alliance = Alliance.find_by_name( alliance_name )
self.alliance_id = alliance.nil? ? 0 : alliance.id
end
def faction_name=( faction_name )
end
def alliance_name
self.alliance.nil? ? 'NONE' : self.alliance.name
end
def details
"#{self.name},#{self.corporation_name},#{self.alliance_name}"
end
## shorthand methods
#
def ship
InvType.find( self.ship_id )
end
## Formatting methods
#
def to_xml( options = {} )
options[:indent] ||= 2
options[:location] ||= false
xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:ident])
xml.instruct! unless options[:skip_instruct]
xml.pilot do
xml.tag!(:id, self.id)
xml.tag!(:victim, true) if self.is_victim
xml.tag!(:finalblow, true) if self.laid_final_blow
xml.tag!(:name, self.name)
xml.corporation do
xml.tag!(:name, self.corporation_name)
self.alliance.to_xml(:skip_instruct => true, :builder => xml) unless self.alliance.nil?
end
xml.ship do
xml.tag!(:name, self.ship.name)
xml.tag!(:weapon, self.weapon_name) unless self.is_victim
end
xml.tag!(:security_status, self.security_status) unless self.is_victim
xml.tag!(:damage, self.damage, :type => self.is_victim ? 'taken' : 'inflicted')
self.solar_system.to_xml(:skip_instruct => true, :builder => xml) if self.is_victim and options[:location]
end
end
end