Class: Bombing
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Bombing
- Defined in:
- lib/galaxy/models/bombing.rb
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(match, state) ⇒ Bombing
constructor
A new instance of Bombing.
- #key ⇒ Object
Constructor Details
#initialize(match, state) ⇒ Bombing
Returns a new instance of Bombing.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/galaxy/models/bombing.rb', line 21 def initialize match, state 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, :attack=>match[10].to_f, :status=>match[11] num = '#' + match[2] unless planet = Planet.lookup(num) args = match[3] == num ? [num] : [match[2], match[3]] planet = Planet.new_or_update args, state.merge({:race=>nil,:product=>nil,:created_by=>self}) end race = Race.lookup(match[0]) victim = Race.lookup(match[1]) prod_name = match[6] product = Product.lookup(prod_name) || Product.lookup(prod_name+'_Research') || Product.lookup(victim.name + '.' + prod_name) || Product.lookup(victim.name + '.' + prod_name+'_Research') # Add this Bombing to appropriate collections it belongs to product.bombings << self planet.bombings << self race.bombings << self victim.incoming_bombings << self add if self.class.dataset # Add instantiated model to dataset if it is established end |
Instance Method Details
#<=>(other) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/galaxy/models/bombing.rb', line 45 def <=>(other) case other when nil then 1 when Bombing then key <=> other.key when Planet then planet <=> other when Product then product <=> other when Race then victim == other ? 0 : race <=> other when Integer then attack <=> other when String then self <=> other.downcase.to_sym when Symbol then return 0 if planet == other return 0 if product == other return 0 if race == other return 0 if victim == other return 0 if status.downcase.include? other.to_s key.downcase <=> other.to_s else raise ArgumentError, 'Comparison with a wrong type' end end |
#key ⇒ Object
43 |
# File 'lib/galaxy/models/bombing.rb', line 43 def key ; [race.name, victim.name, planet.num].join('.') end |