Class: SPNet::NetworkState

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

Overview

Represents a Network object using only serializeable objects.

Author:

  • James Tunnell

Constant Summary collapse

ARG_SPECS =

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

{
  :block_states => arg_spec_hash(:reqd => false, :type => BlockState),
  :link_states => arg_spec_array(:reqd => false, :type => LinkState),
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ NetworkState

A new instance of NetworkState.

Parameters:

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

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



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

def initialize args = {}
  hash_make args, NetworkState::ARG_SPECS
end

Instance Attribute Details

#block_modelsObject (readonly)

Returns the value of attribute block_models.



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

def block_models
  @block_models
end

Returns the value of attribute link_models.



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

def link_models
  @link_models
end

#sample_rateObject (readonly)

Returns the value of attribute sample_rate.



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

def sample_rate
  @sample_rate
end

Instance Method Details

#make_network(args) ⇒ Object

Produce a Network object from the current NetworkState object.

Parameters:

  • args (Hash)

    Hashed arguments. The only key required is :sample_rate.

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/spnet/storage/network_state.rb', line 26

def make_network args
  raise ArgumentError, "args does not have :sample_rate key" unless args.has_key?(:sample_rate)
  sample_rate = args[:sample_rate]
  
  blocks = {}
  @block_states.each do |block_name, block_state|
    blocks[block_name] = block_state.make_block :sample_rate => sample_rate
  end
  
  links = []
  @link_states.each do |link_state|
    links.push link_state.make_link blocks
  end
  
  Network.new :blocks => blocks, :links => links, :sample_rate => sample_rate
end