Sha256: 8978848613a414de823772cfde7b7cc3861f77f6bf3fb5098ee8c3d882e4bf6c

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

module SPNet

# Represent a Link object using only serializeable objects.
#
# @author James Tunnell
class LinkState
  include Hashmake::HashMakeable

  # Define arg specs to use in processing hashed arguments during #initialize.  
  ARG_SPECS = {
    :from => arg_spec(:reqd => true, :type => PortLocater),
    :to => arg_spec(:reqd => true, :type => PortLocater)
  }
  
  attr_reader :from, :to
  
  def initialize args
    hash_make ARG_SPECS, args
  end

  # Make a Link objet from the current LinkState object.  
  def make_link blocks
    raise "from block #{@from.block_name} not found" unless blocks.has_key?(@from.block_name)
    raise "to block #{@to.block_name} not found" unless blocks.has_key?(@to.block_name)
    
    from_block = blocks[@from.block_name]
    to_block = blocks[@to.block_name]
    
    raise "from port #{@from.port_name} not found" unless from_block.out_ports.has_key?(@from.port_name)
    raise "to port #{@to.port_name} not found" unless to_block.in_ports.has_key?(@to.port_name)
    
    from_port = from_block.out_ports[@from.port_name]
    to_port = to_block.in_ports[@to.port_name]
    
    return Link.new(:from => from_port, :to => to_port)
  end
end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spnet-0.1.7 lib/spnet/storage/link_state.rb
spnet-0.1.6 lib/spnet/storage/link_state.rb
spnet-0.1.5 lib/spnet/storage/link_state.rb