Created gem
authormbklein <mbklein@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Tue, 2 Mar 2010 00:13:24 +0000 (00:13 +0000)
committermbklein <mbklein@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Tue, 2 Mar 2010 00:13:24 +0000 (00:13 +0000)
git-svn-id: svn://svn.open-ils.org/ILS-Contrib/acq_edi/trunk@808 6d9bc8c9-1ec2-4278-b937-99fde70a366f

README.rdoc [new file with mode: 0644]
lib/openils/mapper.rb
openils-mapper.gemspec [new file with mode: 0644]

diff --git a/README.rdoc b/README.rdoc
new file mode 100644 (file)
index 0000000..751c47d
--- /dev/null
@@ -0,0 +1,60 @@
+= Introduction
+
+This module adds methods to edi4r's EDI::E::Interchange class to map between EDIFACT, Ruby structures, and JSON strings. It takes JSON input and turns it into valid, well-formatted EDIFACT messages. In order to provide the greatest range of flexibility, the mapper can process two types of input interchangeably: low-level (or raw) and high-level.
+
+== Low-Level
+
+Low-level input describes the exact structure of the required EDIFACT segments and data elements, without having to worry about syntax or exact placement. Any segment, simple data element (DE), or composite data element (CDE) can be specified directly. The tradeoff, of course, is that the application sending the JSON message has to be intimately aware of the underlying EDIFACT message's structure, including all segment and DE/CDE order, data types, and code lists. For example, the following EDIFACT segments describe a vendor (SU) identified by its Standard Address Number (code 31B), and with an internal department code (1865, qualified by the code IA):
+
+  NAD+SU+1556150::31B'
+  RFF+IA:1865'
+
+The low-level JSON representation of those two segments looks like this:
+
+  [
+    'NAD', { '3035' : 'SU', 'C082' : { '3039' : '1556150', '3055' : '31B' }},
+    'RFF', { 'C506' : { '1153' : 'IA', '1154' : '1865' }}
+  ]
+
+In this case, the JSON is more verbose than the raw EDIFACT, but at least it insulates the caller from the details of element order, blank DEs, and character escaping.
+
+== High-Level
+
+The mapper's high-level mode defines a number of pseudo-segments that know how to translate themselves into their low-level counterparts. For example, to create a simple supplier segment with an ID and using the defaults for everything else:
+
+  ['vendor', '1556150']
+  => NAD+SU+1556150::91'
+
+But it's easy to override some of the defaults and add extra segment information as well:
+
+  ['vendor', { 'id' : '1556150', 'id-qual' : '31B', 'reference' : { 'IA' : '1865' }}]
+  => NAD+SU+1556150::31B'
+     RFF+IA:1865'
+
+Another example involves the descriptive metadata sent with each line item in a purchase order. Strings longer than 35 characters have to be split across multiple DEs, and strings longer than 70 characters require multiple iterations of the IMD segment:
+
+  IMD+F+BAU+:::Campbell, James'
+  IMD+F+BTI+:::The Ghost Mountain boys ?: their epi:c march and the terrifying battle f'
+  IMD+F+BTI+:::or New Guinea -- the forgotten war :of the South Pacific'
+  IMD+F+BPU+:::Crown Publishers'
+  IMD+F+BPD+:::2007'''
+
+Note the character escaping (?:) and segmentation (:), as well as the repetition of the IMD title (BTI) field to accommodate the long string. The high level version can look like this:
+
+  [
+  'desc', { 'BAU' : 'Campbell, James' },
+  'desc', { 'BTI' : "The Ghost Mountain boys : their epic march and the terrifying battle for New Guinea -- the forgotten war of the South Pacific" },
+  'desc', { 'BPU' : 'Crown Publishers' },
+  'desc', { 'BPD' : 2007 }
+  ]
+
+or even like this:
+
+  ['desc', [
+    'BAU', 'Campbell, James',
+    'BTI', "The Ghost Mountain boys : their epic march and the terrifying battle for New Guinea -- the forgotten war of the South Pacific",
+    'BPU', 'Crown Publishers',
+    'BPD', 2007
+  ]]
+  
+Since the mapper uses regular expressions and closures to define and evaluate the high-level pseudo-segments, the mapper can be extended very easily (in some cases, trivially), and with great flexibility.
\ No newline at end of file
index a65a165..f37962e 100644 (file)
@@ -3,6 +3,7 @@ require 'edi/mapper'
 module OpenILS
   
   class Mapper < EDI::E::Mapper
+    VERSION = '0.8.2'
   end
   
 end
diff --git a/openils-mapper.gemspec b/openils-mapper.gemspec
new file mode 100644 (file)
index 0000000..76a19ba
--- /dev/null
@@ -0,0 +1,24 @@
+require 'rake'
+begin
+  $: << File.join(File.dirname(__FILE__),'lib')
+  require 'openils/mapper'
+  Gem::Specification.new do |s|
+    s.name = "openils-mapper"
+    s.version = OpenILS::Mapper::VERSION
+    s.summary = "EDIFACT<->JSON middleware for the Evergreen Open Source ILS"
+    s.email = "mbklein@gmail.com"
+    s.description = "Middleware layer to provide translation between high-level JSON and raw EDIFACT messages"
+    s.authors = ["Michael B. Klein"]
+    s.files = FileList["[A-Z]*", "README.rdoc", "{bin,lib,test}/**/*"]
+    s.extra_rdoc_files = ['README.rdoc']
+    s.rdoc_options << '--main' << 'README.rdoc'
+    s.add_dependency 'edi4r', '>= 0.9.4'
+    s.add_dependency 'edi4r-tdid', '>= 0.6.5'
+    s.add_dependency 'json', '>= 1.1.3'
+    s.add_development_dependency 'rcov', '>= 0.8.1'
+    s.add_development_dependency 'rspec', '>= 1.2.2'
+    s.add_development_dependency 'rake', '>= 0.8.0'
+  end
+rescue LoadError
+  puts "Error loading OpenILS::Mapper module."
+end