class SAPNW::RFC::Type

Attributes

decimals[R]
fields[R]
len[R]
name[R]
type[R]
ulen[R]

Public Class Methods

new(*args) click to toggle source
# 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