Class: Cosmos::Entities::Planet

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

Overview

en.wikipedia.org/wiki/Planet

Cosmos entity residing in a solar system orbiting a star.

Constant Summary collapse

CHILD_TYPES =
['Moon']
VALIDATE_SIZE =
proc { |s| (50...60).include?(s)   }
VALIDATE_COLOR =
proc { |c| c =~ /^[a-fA-F0-9]{6}$/ }
RAND_SIZE =
proc { rand(10) + 50               }
RAND_COLOR =
proc { "%06x" % (rand * 0xffffff)  }

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

Cosmos::Planet intializer


31
32
33
34
# File 'lib/cosmos/entities/planet.rb', line 31

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

Class Method Details

.json_create(o) ⇒ Object

Create new planet from json representation


53
54
55
56
# File 'lib/cosmos/entities/planet.rb', line 53

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

Instance Method Details

#to_json(*a) ⇒ Object

Return json representation of planet


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

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 planet is valid.

Currently tests

  • base entity and system entity is valid


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

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