[open-ils-commits] r240 - acq_edi/trunk/lib/edi (mbklein)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Apr 1 14:42:04 EDT 2009
Author: mbklein
Date: 2009-04-01 14:41:58 -0400 (Wed, 01 Apr 2009)
New Revision: 240
Modified:
acq_edi/trunk/lib/edi/mapper.rb
Log:
Added EDI::E::Mapper#finalize method to re-parse the current interchange document
Modified: acq_edi/trunk/lib/edi/mapper.rb
===================================================================
--- acq_edi/trunk/lib/edi/mapper.rb 2009-04-01 16:24:10 UTC (rev 239)
+++ acq_edi/trunk/lib/edi/mapper.rb 2009-04-01 18:41:58 UTC (rev 240)
@@ -1,5 +1,6 @@
require 'edi4r'
require 'edi4r/edifact'
+require 'forwardable'
require 'json'
class String
@@ -14,9 +15,13 @@
module EDI::E
class Mapper
+ extend Forwardable
attr :message
attr_accessor :defaults
+ def_delegators :@ic, :charset, :groups_created, :inspect, :is_iedi?,
+ :messages_created, :output_mode=, :show_una, :show_una=, :to_s,
+ :to_xml, :una, :validate
class << self
def defaults
@@ -73,14 +78,12 @@
handler[:proc].call(self, name, value)
end
- @segments = []
-
def self.from_json(msg_type, json, msg_opts = {}, ic_opts = {})
result = self.new(msg_type, msg_opts, ic_opts)
result.add(JSON.parse(json))
- result
+ result.finalize
end
-
+
def initialize(msg_type, msg_opts = {}, ic_opts = {})
@ic = EDI::E::Interchange.new(ic_opts || {})
@message = @ic.new_message( { :msg_type => msg_type, :version => 'D', :release => '96A', :resp_agency => 'UN' }.merge(msg_opts || {}) )
@@ -101,6 +104,13 @@
end
end
+ def finalize
+ mode = @ic.output_mode
+ @ic = EDI::E::Interchange.parse(StringIO.new(@ic.to_s))
+ @ic.output_mode = mode
+ return self
+ end
+
def to_s
@ic.to_s
end
More information about the open-ils-commits
mailing list