Class: Cosmos::Entities::Galaxy

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

Overview

en.wikipedia.org/wiki/Galaxy

Cosmos entity residing in the Universe, added directly to the Registry. May contain local solar_system children

Constant Summary collapse

PARENT_TYPE =
'NilClass'
CHILD_TYPES =
['SolarSystem']

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 = {}) ⇒ Galaxy

Cosmos::Galaxy intializer


25
26
27
# File 'lib/cosmos/entities/galaxy.rb', line 25

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

Class Method Details

.json_create(o) ⇒ Object

Create new galaxy from json representation


47
48
49
50
# File 'lib/cosmos/entities/galaxy.rb', line 47

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

Instance Method Details

#to_json(*a) ⇒ Object

Return json representation of galaxy


40
41
42
43
44
# File 'lib/cosmos/entities/galaxy.rb', line 40

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

#valid?Boolean

Return boolean indicating if this galaxy is valid.

Currently tests

  • base entity is valid

  • location is stopped

Returns:

  • (Boolean)

34
35
36
37
# File 'lib/cosmos/entities/galaxy.rb', line 34

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