Module: Cosmos::SystemEntity

Includes:
Entity
Included in:
Entities::Asteroid, Entities::JumpGate, Entities::Planet, Entities::Star
Defined in:
lib/cosmos/entity.rb

Overview

Expanded Cosmos Entity which resides in a system and has some basic characteristics.

Assumes class including this defines VALIDATE_SIZE and VALIDATE_COLOR callbacks and RAND_SIZE and RAND_COLOR generators

Constant Summary collapse

PARENT_TYPE =
'SolarSystem'

Instance Attribute Summary collapse

Attributes included from Entity

#children, #id, #location, #metadata, #name, #parent, #parent_id, #proxy_to

Instance Method Summary collapse

Methods included from Entity

#accepts_resource?, #add_child, #each_child, #entity_json, #entity_valid?, #has_child?, #has_children?, #init_entity, #movement_strategy=, #remove_child, #to_s

Instance Attribute Details

#colorObject

Color of entity


197
198
199
# File 'lib/cosmos/entity.rb', line 197

def color
  @color
end

#sizeObject

Size of entity


200
201
202
# File 'lib/cosmos/entity.rb', line 200

def size
  @size
end

Instance Method Details

#init_system_entity(args = {}) ⇒ Object


202
203
204
205
206
# File 'lib/cosmos/entity.rb', line 202

def init_system_entity(args={})
  attr_from_args args, :size  => self.class::RAND_SIZE.call,
                       :color => self.class::RAND_COLOR.call,
                       :solar_system => @parent
end

#system_entity_jsonObject

Return system entity json attributes


219
220
221
# File 'lib/cosmos/entity.rb', line 219

def system_entity_json
  {:color => @color, :size => @size}
end

#system_entity_valid?Boolean

Return boolean indicating if system_entity is valid

Currently tests

  • color is set to valid string

  • size is set to valid value


213
214
215
216
# File 'lib/cosmos/entity.rb', line 213

def system_entity_valid?
  @size.numeric? && self.class::VALIDATE_SIZE.call(@size) &&
  @color.is_a?(String) && self.class::VALIDATE_COLOR.call(@color)
end