Method: SOCMaker::IfcSpc#init_with

Defined in:
lib/soc_maker/ifc_spc.rb

#init_with(coder) ⇒ Object

Constructor: there is one mandatory attributes type and an optional one params.

type

The id of the core-definition, which is instanciated

params

Instanciation parameters



91
92
93
94
95
96
97
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
# File 'lib/soc_maker/ifc_spc.rb', line 91

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 "Name is not defined",
      field: "name" if coder[ 'name' ] == nil
  @name = coder[ 'name' ]

  init_error "Name is not defined as string",
      field: "name" if !@name.is_a?( String )

  init_error "Name has zero length",
      field: "name" if @name.size == 0


  init_error "Id is not defined",
      field: "id"   if coder[ 'id' ] == nil

  @id = coder[ 'id' ]
  init_error "Version 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 = coder[ 'ports' ] || {}
  @ports.each do |pname, port| 

    init_error "Port field must be organized as a hash",
        instance: @name,
        field: "ports" if !port.is_a?( Hash )

    init_error "No port direction specified for #{pname}",
      instance: @name,
      field: "ports" if !port.has_key?( :dir )


    init_error_if(  !port[ :dir ].is_a?( Fixnum ) ||
                 ( port[ :dir ] != 0 && port[ :dir ] != 1 && port[ :dir ] != 2 ) ,
             "Port direction value for #{pname} is neither 0 nor 1 nor 3",
             instance: @name,
             field:    "ports" )

    port[ :mandatory ] = true if !port.has_key?( :mandatory )
    port[ :default ]   ||= '0'

  end

  @multiplicity = coder[ 'multiplicity' ] || [ 1, 1 ]

  init_error "multiplicity must contain exactly two entries " if @multiplicity.size != 2

  @multiplicity.each do |m|
    if !( m.is_a?( Fixnum ) && m >= 0 ||  m.is_a?( String ) && m == "*" )  
      init_error "multiplicity must be a fixnum or the string '*'"
    end
  end

end