Class: Cosmos::Entities::Star

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

Overview

en.wikipedia.org/wiki/Star

Cosmos entity residing in a solar system

Constant Summary collapse

CHILD_TYPES =
[]
VALIDATE_SIZE =
proc { |s| (400...550).include?(s) }
VALIDATE_COLOR =
proc { |c| ['FFFF00'].include?(c)  }
RAND_SIZE =
proc { rand(150) + 400             }
RAND_COLOR =
proc { 'FFFF00'                    }

Constants included from SystemEntity

SystemEntity::PARENT_TYPE

Instance Attribute Summary

Attributes included from SystemEntity

#color, #size

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 SystemEntity

#init_system_entity, #system_entity_json, #system_entity_valid?

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

Cosmos::Star intializer


27
28
29
30
# File 'lib/cosmos/entities/star.rb', line 27

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

Class Method Details

.json_create(o) ⇒ Object

Create new star from json representation


50
51
52
53
# File 'lib/cosmos/entities/star.rb', line 50

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

Instance Method Details

#to_json(*a) ⇒ Object

Return json representation of star


43
44
45
46
47
# File 'lib/cosmos/entities/star.rb', line 43

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

#valid?Boolean

Return boolean indicating if this star is valid.

Currently tests

  • base entity & system entity is valid

  • location is stopped

Returns:

  • (Boolean)

37
38
39
40
# File 'lib/cosmos/entities/star.rb', line 37

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