Class: EDI::Interchange

Inherits:
Object
  • Object
show all
Defined in:
lib/edi4r/rexml.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse_xml(hnd) ⇒ Object

This is a dispatcher method for your convenience, similar to EDI::Interchange.parse. It may be used for all supported EDI standards.

hnd

A REXML document or something that can be turned into one, i.e. an IO object or a String object with corresponding contents

Returns an Interchange object of the subclass specified by the “standard_key” atribute of the root element, e.g. a EDI::E::Interchange.



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/edi4r/rexml.rb', line 99

def Interchange.parse_xml( hnd ) # Handle to REXML document
  unless hnd.is_a? REXML::Document or hnd.is_a? IO or hnd.is_a? String
    raise "Unsupported object type: #{hnd.class}"
  end
  hnd = REXML::Document.new( hnd ) if hnd.is_a? IO or hnd.is_a? String

  key = hnd.root.attributes['standard_key']
  raise "Unsupported standard key: #{key}" if key == 'generic'
  EDI::const_get(key)::const_get('Interchange').parse_xml( hnd )
#      class_sym = (key+'Interchange').intern
#      EDI::const_get(class_sym).parse_xml( hnd )
end

Instance Method Details

#to_xml(xel_parent) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/edi4r/rexml.rb', line 113

def to_xml( xel_parent )
  externalID = "PUBLIC\n" + " "*9
  externalID += "'-//FH Wiesbaden FB DCSM//DTD XML Representation of EDI data V1.2//EN'\n"
  externalID += " "*9
  externalID += "'http://edi01.informatik.fh-wiesbaden.de/edi4r/edi4r-1.2.dtd'"
  xel_parent << REXML::XMLDecl.new
  xel_parent << REXML::DocType.new( normalized_class_name, externalID )

  rc = super

  xel = rc.first
  pos = self.class.to_s =~ /EDI::((.*?)::)?Interchange/
  raise "This is not an Interchange object: #{rc}!" unless pos==0
  xel.attributes["standard_key"] = ($2 and not $2.empty?) ? $2 : "generic"
  xel.attributes["version"] = @version
  xel.attributes.delete "name"
  rc
end