Class: SAPNW::RFC::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/sapnwrfc/parameters.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Type

Returns a new instance of Type.



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/sapnwrfc/parameters.rb', line 272

def initialize(*args)
  args = args.first if args.class == Array and args.first.class == Hash
  case args
    when Array
      name, type, len, ulen, decimals, fields = args
    when Hash
      raise "Missing Type :name => #{args.inspect}\n" unless args.has_key?(:name)
      raise "Missing Type :type => #{args.inspect}\n" unless args.has_key?(:type)
      #raise "Missing Type :len => #{args.inspect}\n" unless args.has_key?(:len)
      case args[:type]
        when SAPNW::RFC::CHAR, SAPNW::RFC::DATE, SAPNW::RFC::BCD, SAPNW::RFC::TIME, SAPNW::RFC::BYTE, SAPNW::RFC::TABLE, SAPNW::RFC::NUM, SAPNW::RFC::FLOAT, SAPNW::RFC::INT, SAPNW::RFC::INT2, SAPNW::RFC::INT1, SAPNW::RFC::NULL, SAPNW::RFC::STRUCTURE, SAPNW::RFC::DECF16, SAPNW::RFC::DECF34, SAPNW::RFC::XMLDATA, SAPNW::RFC::STRING, SAPNW::RFC::XSTRING, SAPNW::RFC::EXCEPTION
        else
          raise "Invalid SAPNW::RFC* type supplied (#{args[:type]})\n"
      end
      len = 0
      ulen = 0
      decimals = 0
      name = args[:name]
      type = args[:type]
      len = args[:len] if args.has_key?(:len)
      ulen = 2 * len
      ulen = args[:ulen] if args.has_key?(:ulen)
      decimals = args[:decimals] if args.has_key?(:decimals)
      fields = args[:fields] if args.has_key?(:fields)
    else
      raise "invalid parameters in SAPNW::RFC::Type: #{args.inspect}\n"
  end
  @name = name
  @type = type
  @len = len
  @ulen = ulen
  @decimals = decimals
  if fields
    raise "Fields must be an Array (#{fields.inspect})\n" unless fields.class == Array
    slen = 0
    sulen = 0
    fields.each do |val|
      raise "each field definition must be a Hash (#{val.inspect})\n" unless val.class == Hash
      unless val.has_key?(:name) and
          val.has_key?(:type) and
          val.has_key?(:len)
        raise "each field definition must have :name, :type, and :len (#{val.inspect})\n"
      end
      val[:ulen] = val[:len] * 2 unless val.has_key?(:ulen)
      val[:decimals] = 0 unless val.has_key?(:decimals)
      slen += val[:len]
      sulen += val[:ulen]
      # sort out nested types
      if val[:type].class == SAPNW::RFC::Type
        val[:typedef] = val[:type]
        val[:type] = val[:typedef].type
      end
    end
    @len = slen unless @len > 0
    @ulen = sulen unless @ulen > 0
  end
  @fields = fields
  #$stderr.print "initilised Type(#{name}): #{type} - #{@fields.inspect}\n"
end

Instance Attribute Details

#decimalsObject (readonly)

Returns the value of attribute decimals.



270
271
272
# File 'lib/sapnwrfc/parameters.rb', line 270

def decimals
  @decimals
end

#fieldsObject (readonly)

Returns the value of attribute fields.



270
271
272
# File 'lib/sapnwrfc/parameters.rb', line 270

def fields
  @fields
end

#lenObject (readonly)

Returns the value of attribute len.



270
271
272
# File 'lib/sapnwrfc/parameters.rb', line 270

def len
  @len
end

#nameObject (readonly)

Returns the value of attribute name.



270
271
272
# File 'lib/sapnwrfc/parameters.rb', line 270

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



270
271
272
# File 'lib/sapnwrfc/parameters.rb', line 270

def type
  @type
end

#ulenObject (readonly)

Returns the value of attribute ulen.



270
271
272
# File 'lib/sapnwrfc/parameters.rb', line 270

def ulen
  @ulen
end