Class: SPNet::BlockState

Inherits:
Object
  • Object
show all
Includes:
Hashmake::HashMakeable
Defined in:
lib/spnet/storage/block_state.rb

Overview

Represent a Block object using only serializeable objects.

Author:

  • James Tunnell

Constant Summary collapse

ARG_SPECS =

Define arg specs to use in processing hashed arguments during #initialize.

{
  :class_sym => arg_spec(:reqd => true, :type => Symbol),
  :params => arg_spec_hash(:reqd => false, :type => Object),
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ BlockState

A new instance of NetworkState.

Parameters:

  • args (Hash)

    Hashed arguments for initialization. See Network::ARG_SPECS for details of which keys are required.



20
21
22
# File 'lib/spnet/storage/block_state.rb', line 20

def initialize args
  hash_make args, BlockState::ARG_SPECS
end

Instance Attribute Details

#class_symObject (readonly)

Returns the value of attribute class_sym.



15
16
17
# File 'lib/spnet/storage/block_state.rb', line 15

def class_sym
  @class_sym
end

#paramsObject (readonly)

Returns the value of attribute params.



15
16
17
# File 'lib/spnet/storage/block_state.rb', line 15

def params
  @params
end

Instance Method Details

#make_block(args) ⇒ Object

Produce a Block object from the current BlockState object.

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
33
# File 'lib/spnet/storage/block_state.rb', line 25

def make_block args
  raise ArgumentError, "args does not have :sample_rate key" unless args.has_key?(:sample_rate)
  
  klass = find_class(@class_sym)
  block = klass.new :sample_rate => args[:sample_rate]
  block.restore_state self
  
  return block
end