Class: SOCMaker::IfcPort

Inherits:
Object
  • Object
show all
Includes:
ERR
Defined in:
lib/soc_maker/ifc_port.rb

Overview

A small classes, used to group information and to verify, auto-correct and auto-complete this information: The class represents an interface port within SOCMaker::IfcDef. It is used to make a relation between the naming of SOCMaker::IfcDef and SOCMaker::IfcSpc. The two data fiels are

  • #spc_ref (mandatory: must be the name of the port, defined in IfcSpc)

  • #len (optional, default is 1)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ERR

#consistence_error, #consistence_error_if, #init_error, #init_error_if, #processing_error, #processing_error_if

Constructor Details

#initialize(spc_ref, len = 1) ⇒ IfcPort

Constructor, which expects #spc_ref and #len. Length has the default value 1.



71
72
73
74
# File 'lib/soc_maker/ifc_port.rb', line 71

def initialize( spc_ref, len = 1 )
  init_with( 'spc_ref' => spc_ref,
             'len'  => len )
end

Instance Attribute Details

#lenObject

Length of this port



65
66
67
# File 'lib/soc_maker/ifc_port.rb', line 65

def len
  @len
end

#spc_refObject

Used as reference to a port in SOCMaker::IfcSpc



60
61
62
# File 'lib/soc_maker/ifc_port.rb', line 60

def spc_ref
  @spc_ref
end

Instance Method Details

#==(o) ⇒ Object

Equality operator



125
126
127
128
129
# File 'lib/soc_maker/ifc_port.rb', line 125

def ==(o)
  o.class   == self.class     && 
  o.spc_ref == self.spc_ref   &&
  o.len     == self.len 
end

#encode_with(coder) ⇒ Object

Encoder method (to yaml)

coder

An instance of the Psych::Coder to encode this class to a YAML file



82
83
84
85
86
87
88
# File 'lib/soc_maker/ifc_port.rb', line 82

def encode_with( coder )

  init_error_if !coder.is_a?( Psych::Coder ), 
              'coder is not given as Psych::Coder'
  %w[ spc_ref len ].
        each { |v| coder[ v ] = instance_variable_get "@#{v}" }
end

#init_with(coder) ⇒ Object

Initialization method (from yaml)

coder

An instance of the Psych::Coder to init this class from a YAML file



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/soc_maker/ifc_port.rb', line 96

def init_with( coder )

  init_error_if !( coder.is_a?( Hash ) || coder.is_a?( Psych::Coder ) ), 
              'coder is not given as Hash neither as Psych::Coder'

  init_error 'no relation to interface-definition is given for an interface port (nil)',
    field: "spc_ref" if coder[ 'spc_ref' ] == nil
  @spc_ref = coder[ 'spc_ref' ]

  init_error 'Relation to interface definition is not of type string',
    instance: @spc_ref.to_s,
    field:    "spc_ref" if  !@spc_ref.is_a?( String )

  init_error 'Relation to interface definition has zero length',
    instance: @spc_ref.to_s,
    field:    "spc_ref" if @spc_ref.size == 0

  @len = coder[ 'len' ] || 1

  init_error 'Length is not a fixnum',
    instance: @spc_ref.to_s,
    field:    "spc_ref" if !( @len.is_a?( Fixnum ) || @len.is_a?( String ) )
end