galaxy 0.0.2
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/.document +5 -0
- data/.gitignore +21 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/galaxy.iml +10 -0
- data/.idea/misc.xml +14 -0
- data/.idea/modules.xml +9 -0
- data/.idea/vcs.xml +8 -0
- data/.idea/workspace.xml +486 -0
- data/LICENSE +20 -0
- data/README.rdoc +36 -0
- data/Rakefile +62 -0
- data/VERSION +1 -0
- data/doc/plan.txt +5 -0
- data/doc/pseudo.txt +43 -0
- data/features/galaxy.feature +9 -0
- data/features/step_definitions/galaxy_steps.rb +0 -0
- data/features/support/env.rb +4 -0
- data/galaxy.gemspec +95 -0
- data/galaxy/.loadpath +5 -0
- data/galaxy/.project +17 -0
- data/galaxy/.settings/org.eclipse.mylyn.tasks.ui.prefs +4 -0
- data/galaxy/.settings/org.eclipse.wst.sse.core.prefs +5 -0
- data/galaxy/experiments.rb +26 -0
- data/lib/galaxy.rb +8 -0
- data/lib/galaxy/models/bombing.rb +64 -0
- data/lib/galaxy/models/fleet.rb +62 -0
- data/lib/galaxy/models/group.rb +178 -0
- data/lib/galaxy/models/models.rb +16 -0
- data/lib/galaxy/models/planet.rb +181 -0
- data/lib/galaxy/models/product.rb +84 -0
- data/lib/galaxy/models/race.rb +112 -0
- data/lib/galaxy/models/route.rb +60 -0
- data/lib/galaxy/order.rb +24 -0
- data/lib/galaxy/report.rb +176 -0
- data/lib/galaxy/section.rb +226 -0
- data/lib/galaxy/utils.rb +109 -0
- data/lib/galaxy/virtual_base.rb +165 -0
- data/spec/spec_helper.rb +9 -0
- data/test/test_helper.rb +4 -0
- data/test/unit/models_test.rb +1469 -0
- data/test/unit/report_test.rb +187 -0
- data/test/unit/utils_test.rb +421 -0
- data/test/unit/virtual_base_test.rb +224 -0
- metadata +123 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 arvicco
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
= win
|
2
|
+
|
3
|
+
by: Arvicco
|
4
|
+
url: http://github.com/arvicco/win
|
5
|
+
|
6
|
+
== DESCRIPTION
|
7
|
+
|
8
|
+
Report parser and scripting tool for Galaxy Plus.
|
9
|
+
|
10
|
+
== SUMMARY
|
11
|
+
|
12
|
+
Galaxy Plus is a play-by-email (PBEM) game that was very popular some time ago.
|
13
|
+
This code allows you to parse Galaxy Plus / Dragon Galaxy report files and builds
|
14
|
+
ActiveRecord models for its data artifacts. you can further use these artifacts to
|
15
|
+
build automation scripts and whatnot. I have used this tool to efficiently manage
|
16
|
+
even such monstrous game format as 'research', with literally thousands of planets
|
17
|
+
and tens of thousands ship groups to take care of each turn.
|
18
|
+
|
19
|
+
This gem does not include specific automation add-ons (mine were too specific and
|
20
|
+
tightly integrated into external scripting frameworks). However, you can easily build
|
21
|
+
such scripts on top of data models provided here.
|
22
|
+
|
23
|
+
Since I do not play Galaxy Plus any longer, no further development of this code is
|
24
|
+
expected from my side, so I release it into public domain for anyone to use and enjoy.
|
25
|
+
|
26
|
+
== INSTALLATION
|
27
|
+
|
28
|
+
$ gem install galaxy
|
29
|
+
|
30
|
+
== SYNOPSIS
|
31
|
+
|
32
|
+
Please see tests for proper examples of usage.
|
33
|
+
|
34
|
+
== Copyright
|
35
|
+
|
36
|
+
Copyright (c) 2004-2010 arvicco. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "galaxy"
|
8
|
+
gem.summary = %Q{Report parser for Galaxy Plus PBEM}
|
9
|
+
gem.description = %Q{Report parser for Galaxy Plus PBEM}
|
10
|
+
gem.email = "arvitallian@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/arvicco/galaxy"
|
12
|
+
gem.authors = ["arvicco"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.add_development_dependency "cucumber", ">= 0"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:test) do |t|
|
24
|
+
t.ruby_opts = ['-r test/unit' ]
|
25
|
+
t.spec_files = FileList['test/unit/*_test.rb' ]
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
31
|
+
end
|
32
|
+
|
33
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
34
|
+
spec.libs << 'lib' << 'spec'
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :spec => :check_dependencies
|
40
|
+
|
41
|
+
begin
|
42
|
+
require 'cucumber/rake/task'
|
43
|
+
Cucumber::Rake::Task.new(:features)
|
44
|
+
|
45
|
+
task :features => :check_dependencies
|
46
|
+
rescue LoadError
|
47
|
+
task :features do
|
48
|
+
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
task :default => :spec
|
53
|
+
|
54
|
+
require 'rake/rdoctask'
|
55
|
+
Rake::RDocTask.new do |rdoc|
|
56
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
57
|
+
|
58
|
+
rdoc.rdoc_dir = 'rdoc'
|
59
|
+
rdoc.title = "galaxy #{version}"
|
60
|
+
rdoc.rdoc_files.include('README*')
|
61
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
62
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/doc/plan.txt
ADDED
data/doc/pseudo.txt
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#readfile
|
2
|
+
|
3
|
+
#find begin/end of Races section
|
4
|
+
#scan races (simple, no recursion)
|
5
|
+
|
6
|
+
#find begin/end of Sciences section
|
7
|
+
#for each race in the section
|
8
|
+
#scan sciences
|
9
|
+
|
10
|
+
#find begin/end of Ship Types section
|
11
|
+
#for each race in the section
|
12
|
+
#scan ship types
|
13
|
+
|
14
|
+
#find begin/end of Battles section
|
15
|
+
#for each battle in the section
|
16
|
+
#find begin/end of battle ( .."Battle Protocol")
|
17
|
+
#for each race in the battle
|
18
|
+
#scan ship list
|
19
|
+
|
20
|
+
#find begin/end of Bombings section
|
21
|
+
#scan bombings (simple, no recursion)
|
22
|
+
|
23
|
+
#find begin/end of Incoming Groups section
|
24
|
+
#scan incomings (simple, no recursion)
|
25
|
+
|
26
|
+
#find begin/end of Planets section
|
27
|
+
#scan your planets
|
28
|
+
#scan your ships_in_production?
|
29
|
+
#scan routes?
|
30
|
+
#for each race in the section
|
31
|
+
#scan planets
|
32
|
+
#scan Uninhabited planets
|
33
|
+
#scan Unidentified planets
|
34
|
+
|
35
|
+
#find begin/end of Fleets section
|
36
|
+
#scan your fleets (simple, no recursion)
|
37
|
+
|
38
|
+
#find begin/end of Groups section
|
39
|
+
#scan your groups (with numbers)
|
40
|
+
#for each race in the section
|
41
|
+
#scan groups
|
42
|
+
#scan Unidentified groups
|
43
|
+
|
File without changes
|
data/galaxy.gemspec
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{galaxy}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["arvicco"]
|
12
|
+
s.date = %q{2010-03-11}
|
13
|
+
s.description = %q{Report parser for Galaxy Plus PBEM}
|
14
|
+
s.email = %q{arvitallian@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
".idea/.rakeTasks",
|
23
|
+
".idea/encodings.xml",
|
24
|
+
".idea/galaxy.iml",
|
25
|
+
".idea/misc.xml",
|
26
|
+
".idea/modules.xml",
|
27
|
+
".idea/vcs.xml",
|
28
|
+
".idea/workspace.xml",
|
29
|
+
"LICENSE",
|
30
|
+
"README.rdoc",
|
31
|
+
"Rakefile",
|
32
|
+
"VERSION",
|
33
|
+
"doc/plan.txt",
|
34
|
+
"doc/pseudo.txt",
|
35
|
+
"features/galaxy.feature",
|
36
|
+
"features/step_definitions/galaxy_steps.rb",
|
37
|
+
"features/support/env.rb",
|
38
|
+
"galaxy.gemspec",
|
39
|
+
"galaxy/.loadpath",
|
40
|
+
"galaxy/.project",
|
41
|
+
"galaxy/.settings/org.eclipse.mylyn.tasks.ui.prefs",
|
42
|
+
"galaxy/.settings/org.eclipse.wst.sse.core.prefs",
|
43
|
+
"galaxy/experiments.rb",
|
44
|
+
"lib/galaxy.rb",
|
45
|
+
"lib/galaxy/models/bombing.rb",
|
46
|
+
"lib/galaxy/models/fleet.rb",
|
47
|
+
"lib/galaxy/models/group.rb",
|
48
|
+
"lib/galaxy/models/models.rb",
|
49
|
+
"lib/galaxy/models/planet.rb",
|
50
|
+
"lib/galaxy/models/product.rb",
|
51
|
+
"lib/galaxy/models/race.rb",
|
52
|
+
"lib/galaxy/models/route.rb",
|
53
|
+
"lib/galaxy/order.rb",
|
54
|
+
"lib/galaxy/report.rb",
|
55
|
+
"lib/galaxy/section.rb",
|
56
|
+
"lib/galaxy/utils.rb",
|
57
|
+
"lib/galaxy/virtual_base.rb",
|
58
|
+
"spec/spec_helper.rb",
|
59
|
+
"test/test_helper.rb",
|
60
|
+
"test/unit/models_test.rb",
|
61
|
+
"test/unit/report_test.rb",
|
62
|
+
"test/unit/utils_test.rb",
|
63
|
+
"test/unit/virtual_base_test.rb"
|
64
|
+
]
|
65
|
+
s.homepage = %q{http://github.com/arvicco/galaxy}
|
66
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
67
|
+
s.require_paths = ["lib"]
|
68
|
+
s.rubygems_version = %q{1.3.5}
|
69
|
+
s.summary = %q{Report parser for Galaxy Plus PBEM}
|
70
|
+
s.test_files = [
|
71
|
+
"spec/spec_helper.rb",
|
72
|
+
"test/test_helper.rb",
|
73
|
+
"test/unit/models_test.rb",
|
74
|
+
"test/unit/report_test.rb",
|
75
|
+
"test/unit/utils_test.rb",
|
76
|
+
"test/unit/virtual_base_test.rb"
|
77
|
+
]
|
78
|
+
|
79
|
+
if s.respond_to? :specification_version then
|
80
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
81
|
+
s.specification_version = 3
|
82
|
+
|
83
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
84
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
85
|
+
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
86
|
+
else
|
87
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
88
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
89
|
+
end
|
90
|
+
else
|
91
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
92
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
data/galaxy/.loadpath
ADDED
data/galaxy/.project
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>galaxy</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
<buildCommand>
|
9
|
+
<name>org.rubypeople.rdt.core.rubybuilder</name>
|
10
|
+
<arguments>
|
11
|
+
</arguments>
|
12
|
+
</buildCommand>
|
13
|
+
</buildSpec>
|
14
|
+
<natures>
|
15
|
+
<nature>org.rubypeople.rdt.core.rubynature</nature>
|
16
|
+
</natures>
|
17
|
+
</projectDescription>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#require 'models.rb'
|
2
|
+
require 'report.rb'
|
3
|
+
#Default_footer = 'default'
|
4
|
+
@name = 'Bombings'
|
5
|
+
@footer = 'Pre-value'
|
6
|
+
@footer = @footer || Regexen.const_get('rDefault_footer') rescue 'Fuck!' #if Regexen.const_defined?(:Default_footer) then Regexen.const_get(:Default_footer) end
|
7
|
+
|
8
|
+
p @footer
|
9
|
+
|
10
|
+
##Open Report
|
11
|
+
#start = Time.now
|
12
|
+
#rep = Report.new "rep/ArVit081.rep"
|
13
|
+
#
|
14
|
+
#printf "Length: #{rep.text.length} #{Time.now} Elapsed: #{Time.now-start}\n"
|
15
|
+
#
|
16
|
+
## Parse Report (possibly many times)
|
17
|
+
#start = Time.now
|
18
|
+
#1.times do rep.parse end
|
19
|
+
#
|
20
|
+
#printf "#{Time.now} Elapsed: #{Time.now-start}\n"
|
21
|
+
#
|
22
|
+
#puts rep.status
|
23
|
+
#
|
24
|
+
#p rep.races[5], rep.sciences[5], rep.designs[5], rep.battle_groups[5], rep.bombings[0], rep.incoming_groups[0],
|
25
|
+
#rep.your_planets[5], rep.planets[145], rep.unidentified_planets[5], rep.uninhabited_planets[5],
|
26
|
+
#rep.routes[0], rep.fleets[0], rep.groups[5], rep.your_groups[5], rep.unidentified_groups[5]
|
data/lib/galaxy.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# Used to auto-require all the source files located in lib/...
|
2
|
+
def self.require_libs( filename, filemask )
|
3
|
+
file = ::File.expand_path(::File.join(::File.dirname(filename), filemask.gsub(/(?<!.rb)$/,'.rb')))
|
4
|
+
require file if File.exist?(file) && !File.directory?(file)
|
5
|
+
Dir.glob(file).sort.each {|rb| require rb}
|
6
|
+
end
|
7
|
+
|
8
|
+
%W[galaxy/virtual_base galaxy/models/models galaxy/*].each {|rb| require_libs(__FILE__, rb)}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#TAG bombing.rb tasks are on
|
2
|
+
require 'galaxy/models/models'
|
3
|
+
|
4
|
+
class Bombing < ActiveRecord::Base
|
5
|
+
virtual
|
6
|
+
tableless :columns => [
|
7
|
+
[ :pop, :float ],
|
8
|
+
[ :ind, :float ],
|
9
|
+
[ :cap, :float ],
|
10
|
+
[ :mat, :float ],
|
11
|
+
[ :col, :float ],
|
12
|
+
[ :attack, :float ],
|
13
|
+
[ :status, :string ]
|
14
|
+
]
|
15
|
+
|
16
|
+
belongs_to :planet
|
17
|
+
belongs_to :product #special syntax(no _Research for sciences)!
|
18
|
+
belongs_to :race
|
19
|
+
belongs_to :victim, :class_name => "Race"
|
20
|
+
|
21
|
+
def initialize match, state
|
22
|
+
super :pop=>match[4].to_f, :ind=>match[5].to_f, :cap=>match[7].to_f, :mat=>match[8].to_f, :col=>match[9].to_f,
|
23
|
+
:attack=>match[10].to_f, :status=>match[11]
|
24
|
+
|
25
|
+
num = '#' + match[2]
|
26
|
+
unless planet = Planet.lookup(num)
|
27
|
+
args = match[3] == num ? [num] : [match[2], match[3]]
|
28
|
+
planet = Planet.new_or_update args, state.merge({:race=>nil,:product=>nil,:created_by=>self})
|
29
|
+
end
|
30
|
+
race = Race.lookup(match[0])
|
31
|
+
victim = Race.lookup(match[1])
|
32
|
+
prod_name = match[6]
|
33
|
+
product = Product.lookup(prod_name) || Product.lookup(prod_name+'_Research') || Product.lookup(victim.name + '.' + prod_name) || Product.lookup(victim.name + '.' + prod_name+'_Research')
|
34
|
+
|
35
|
+
# Add this Bombing to appropriate collections it belongs to
|
36
|
+
product.bombings << self
|
37
|
+
planet.bombings << self
|
38
|
+
race.bombings << self
|
39
|
+
victim.incoming_bombings << self
|
40
|
+
add if self.class.dataset # Add instantiated model to dataset if it is established
|
41
|
+
end
|
42
|
+
|
43
|
+
def key ; [race.name, victim.name, planet.num].join('.') end
|
44
|
+
|
45
|
+
def <=>(other)
|
46
|
+
case other
|
47
|
+
when nil then 1
|
48
|
+
when Bombing then key <=> other.key
|
49
|
+
when Planet then planet <=> other
|
50
|
+
when Product then product <=> other
|
51
|
+
when Race then victim == other ? 0 : race <=> other
|
52
|
+
when Integer then attack <=> other
|
53
|
+
when String then self <=> other.downcase.to_sym
|
54
|
+
when Symbol then
|
55
|
+
return 0 if planet == other
|
56
|
+
return 0 if product == other
|
57
|
+
return 0 if race == other
|
58
|
+
return 0 if victim == other
|
59
|
+
return 0 if status.downcase.include? other.to_s
|
60
|
+
key.downcase <=> other.to_s
|
61
|
+
else raise ArgumentError, 'Comparison with a wrong type'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end #Bombing
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'galaxy/models/models'
|
2
|
+
|
3
|
+
class Fleet < ActiveRecord::Base
|
4
|
+
virtual
|
5
|
+
tableless :columns => [
|
6
|
+
[ :num, :integer ],
|
7
|
+
[ :name, :string ],
|
8
|
+
[ :num_groups, :integer ],
|
9
|
+
[ :range, :float ],
|
10
|
+
[ :speed, :float ],
|
11
|
+
[ :status, :string ] # May cause problems with AR?
|
12
|
+
]
|
13
|
+
belongs_to :race
|
14
|
+
belongs_to :planet
|
15
|
+
belongs_to :from, :class_name => 'Planet'
|
16
|
+
has_many_linked :groups
|
17
|
+
|
18
|
+
def initialize match, state
|
19
|
+
super :num=>match[0].to_i, :name=>match[1], :num_groups=>match[2].to_i, :range=>match[5].to_f,
|
20
|
+
:speed=>match[6].to_f, :status=>match[7]
|
21
|
+
|
22
|
+
planet = Planet.new_or_update[match[3]], state.merge({:race=>nil,:product=>nil,:created_by=>self}) unless planet = Planet.lookup(match[3])
|
23
|
+
from = Planet.new_or_update [match[4]], state.merge({:race=>nil,:product=>nil,:created_by=>self}) unless from = Planet.lookup(match[4]) unless match[4] == '-'
|
24
|
+
race = Race.lookup(state[:owner])
|
25
|
+
|
26
|
+
planet.fleets << self
|
27
|
+
from.sent_fleets << self if from
|
28
|
+
race.fleets << self
|
29
|
+
add if self.class.dataset # Add instantiated model to dataset if it is defined
|
30
|
+
end
|
31
|
+
|
32
|
+
def eta ; from ? range/speed : 0 end
|
33
|
+
|
34
|
+
def destination ; planet end
|
35
|
+
|
36
|
+
def source ; from end
|
37
|
+
alias origin source
|
38
|
+
|
39
|
+
def key ; race.name + '.' + name end
|
40
|
+
|
41
|
+
def <=>(other)
|
42
|
+
case other
|
43
|
+
when nil then 1
|
44
|
+
when Fleet then key <=> other.key
|
45
|
+
when Race then race <=> other
|
46
|
+
when Planet then
|
47
|
+
return 0 if from and from == other
|
48
|
+
self.planet <=> other
|
49
|
+
when Group then groups.any? {|g| g == other} ? 0 : 1 # Fleet always bigger than Group
|
50
|
+
when Integer then num_groups <=> other
|
51
|
+
when String then self <=> other.downcase.to_sym
|
52
|
+
when Symbol then
|
53
|
+
return 0 if race and race == other
|
54
|
+
return 0 if planet and planet == other
|
55
|
+
return 0 if from and from == other
|
56
|
+
return 0 if status.downcase.include? other.to_s
|
57
|
+
return 0 if key.downcase.include? other.to_s
|
58
|
+
key.downcase <=> other.to_s
|
59
|
+
else raise ArgumentError, 'Comparison with a wrong type'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end #Fleet
|