Class: SOCMaker::IfcDef
- Inherits:
-
Object
- Object
- SOCMaker::IfcDef
- Includes:
- ERR
- Defined in:
- lib/soc_maker/ifc_def.rb
Overview
A small classes, used to group information and to verify, auto-correct and auto-complete this information: The class represents an interface definition containing
-
a #name of the interface (mandatory)
-
an #id of the instance (mandatory)
-
a #dir (direction) (mandatory)
-
some #ports (hash of type SOCMaker::IfcPort, mandatory)
Note: instances of this class are used withing core-definitions. Different cores may use the same interface, but with a different naming of the ports. For this reason, the id is used to identify, which interface specification (SOCMaker::IfcSpc) is defined. The port-hash makes the relation between the core port-naming and the IfcSpc port-naming.
Instance Attribute Summary collapse
-
#dir ⇒ Object
direction.
-
#id ⇒ Object
id of the interface specification.
-
#name ⇒ Object
name of interface definition.
-
#ports ⇒ Object
the port hash, containing the IfcPort instances.
Instance Method Summary collapse
-
#==(o) ⇒ Object
Equality operator.
-
#consistence_check ⇒ Object
Runs a consistence check: it ensures, that the port-reference is unique.
-
#encode_with(coder) ⇒ Object
Encoder method (to yaml).
-
#init_with(coder) ⇒ Object
Initialization method (from yaml).
-
#initialize(name, id, dir, ports) ⇒ IfcDef
constructor
The constructor expects a name, id, dir (direction) and ports as mandatory arguments.
Methods included from ERR
#consistence_error, #consistence_error_if, #init_error, #init_error_if, #processing_error, #processing_error_if
Constructor Details
#initialize(name, id, dir, ports) ⇒ IfcDef
The constructor expects a name, id, dir (direction) and ports as mandatory arguments.
72 73 74 75 76 77 |
# File 'lib/soc_maker/ifc_def.rb', line 72 def initialize( name, id, dir, ports ) init_with( 'name' => name, 'dir' => dir, 'id' => id, 'ports' => ports ) end |
Instance Attribute Details
#dir ⇒ Object
direction
62 63 64 |
# File 'lib/soc_maker/ifc_def.rb', line 62 def dir @dir end |
#id ⇒ Object
id of the interface specification
65 66 67 |
# File 'lib/soc_maker/ifc_def.rb', line 65 def id @id end |
#name ⇒ Object
name of interface definition
59 60 61 |
# File 'lib/soc_maker/ifc_def.rb', line 59 def name @name end |
#ports ⇒ Object
the port hash, containing the IfcPort instances
68 69 70 |
# File 'lib/soc_maker/ifc_def.rb', line 68 def ports @ports end |
Instance Method Details
#==(o) ⇒ Object
Equality operator
183 184 185 186 187 188 189 |
# File 'lib/soc_maker/ifc_def.rb', line 183 def ==(o) o.class == self.class && o.name == self.name && o.dir == self.dir && o.id == self.id && o.ports == self.ports end |
#consistence_check ⇒ Object
Runs a consistence check: it ensures, that the port-reference is unique.
172 173 174 175 176 177 |
# File 'lib/soc_maker/ifc_def.rb', line 172 def consistence_check tmp = {} ports.each {|k,v| tmp[v.spc_ref] = k} consistence_error "The port reference must be unique", name: @name if ports.size != tmp.size end |
#encode_with(coder) ⇒ Object
Encoder method (to yaml)
coder
-
An instance of the Psych::Coder to encode this class to a YAML file
84 85 86 87 88 89 90 |
# File 'lib/soc_maker/ifc_def.rb', line 84 def encode_with( coder ) init_error_if !coder.is_a?( Psych::Coder ), 'coder is not given as Psych::Coder' %w[ name dir ports ]. each { |v| coder[ v ] = instance_variable_get "@#{v}" } coder[ "id" ] = @id.to_s end |
#init_with(coder) ⇒ Object
Initialization method (from yaml)
coder
-
An instance of the Psych::Coder to init this class from a YAML file
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/soc_maker/ifc_def.rb', line 98 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' # name init_error 'no name defined for this interface', field: 'name' if coder[ 'name' ] == nil @name = coder[ 'name' ] init_error 'Interface name is not defined as string', instance: @name, field: 'name' if !@name.is_a?( String ) init_error "Name has zero length", field: "name" if @name.size == 0 # id init_error 'id is not given for interface', instance: @name, field: 'id' if coder[ 'id' ] == nil init_error 'Interface id is not defined as string', instance: @name, field: 'id' if !coder[ 'id' ].is_a?( String ) init_error "Version has zero length", field: "name" if coder[ 'id' ].size == 0 @id = coder[ 'id' ].to_sym # ports init_error "No ports are given for interface definition", field: 'ports' if coder[ 'ports' ] == nil @ports = coder[ 'ports' ] init_error 'no ports are given for this interface', instance: @name, field: 'ports' if !@ports.is_a?( Hash ) || @ports.size == 0 @ports.each do |name, port| init_error 'no interface port found', instance: @name + name.to_s, field: 'ports' if port == nil init_error 'Port is not of type SocMaker::IfcPort (use SOCM_PORT)', instance: @name + name.to_s, field: 'ports' if !port.is_a?( SOCMaker::IfcPort ) end # direction init_error 'Interface direction is not given', instance: @name, field: 'dir' if coder[ 'dir' ] == nil @dir = coder[ 'dir' ] init_error 'Interface direction must be 0 or 1', instance: @name, value: coder['dir' ], field: 'dir' if @dir != 0 && @dir != 1 end |