Class: Cosmos::Entities::Moon

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

Overview

en.wikipedia.org/wiki/Natural_satellite

Cosmos entity existing in proximity to a Planet.

Currently does not orbit but that will be changed in the future

Constant Summary collapse

PARENT_TYPE =
'Planet'
CHILD_TYPES =
[]

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

Cosmos::Moon intializer

Parameters:

  • args (Hash) (defaults to: {})

    hash of options to initialize moon with


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

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

  attr_from_args args, :planet => @parent
end

Class Method Details

.json_create(o) ⇒ Object

Create new moon from json representation


51
52
53
54
# File 'lib/cosmos/entities/moon.rb', line 51

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

Instance Method Details

#to_json(*a) ⇒ Object

Return json representation of moon


44
45
46
47
48
# File 'lib/cosmos/entities/moon.rb', line 44

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

#valid?Boolean

Return boolean indicating if this moon is valid.

Currently tests

  • base entity is valid

  • location is not moving

Returns:

  • (Boolean)

38
39
40
41
# File 'lib/cosmos/entities/moon.rb', line 38

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