Class: Cosmos::Entities::SolarSystem

Inherits:
Object
  • Object
show all
Includes:
Cosmos::Entity
Defined in:
lib/cosmos/entities/solar_system.rb

Overview

en.wikipedia.org/wiki/Planetary_system

Cosmos entity residing in a galaxy containing stars, planets, asteroid, and jump gates.

Constant Summary collapse

PARENT_TYPE =
'Galaxy'
CHILD_TYPES =
['Star', 'Planet', 'JumpGate', 'Asteroid']

Instance Attribute Summary

Attributes included from Cosmos::Entity

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Cosmos::Entity

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

Constructor Details

#initialize(args = {}) ⇒ SolarSystem

Cosmos::SolarSystem intializer


41
42
43
44
45
# File 'lib/cosmos/entities/solar_system.rb', line 41

def initialize(args = {})
  init_entity(args)

  attr_from_args args, :galaxy => @parent
end

Class Method Details

.json_create(o) ⇒ Object

Create new solar system from json representation


65
66
67
68
# File 'lib/cosmos/entities/solar_system.rb', line 65

def self.json_create(o)
  s = new(o['data'])
  return s
end

Instance Method Details

#asteroidsObject

Array of child Asteroid


38
# File 'lib/cosmos/entities/solar_system.rb', line 38

def asteroids  ; children.select { |c| c.is_a?(Asteroid) } end

#jump_gatesObject

Array of child JumpGate


35
# File 'lib/cosmos/entities/solar_system.rb', line 35

def jump_gates ; children.select { |c| c.is_a?(JumpGate) } end

#planetsObject

Array of child Planets


32
# File 'lib/cosmos/entities/solar_system.rb', line 32

def planets    ; children.select { |c| c.is_a?(Planet) }   end

#starObject

First child Star


29
# File 'lib/cosmos/entities/solar_system.rb', line 29

def star       ; stars.first                               end

#starsObject

Array of child Stars


26
# File 'lib/cosmos/entities/solar_system.rb', line 26

def stars      ; children.select { |c| c.is_a?(Star) }     end

#to_json(*a) ⇒ Object

Return json representation of solar system


58
59
60
61
62
# File 'lib/cosmos/entities/solar_system.rb', line 58

def to_json(*a)
  { :json_class => self.class.name,
    :data       => entity_json
  }.to_json(*a)
end

#valid?Boolean

Return boolean indicating if this solar system is valid.

Currently tests

  • base entity is valid

  • location is stopped


52
53
54
55
# File 'lib/cosmos/entities/solar_system.rb', line 52

def valid?
  entity_valid? &&
  @location.movement_strategy.is_a?(Motel::MovementStrategies::Stopped)
end