class EDI::Diagram::Diagram

Diagram: A structure class to represent a message diagram (branching diagram)

A Diagram is essentially

In contrast to a simple Branch, all nodes of a Diagram object are indexed (counting from 1) according to their natural sequence in the EDIFACT branching diagram. Thus, access by index is available for Diagram objects, but not for Branch objects.

Public Class Methods

caching?() click to toggle source

Tells if caching is currently activated (returns a boolean)

# File lib/edi4r/diagrams.rb, line 84
def Diagram.caching?
  @@caching
end
caching_off() click to toggle source

A Diagram can become quite complex and memory-consuming. Therefore diagrams are cached after creation, so that they need to be created and maintained only once when there are several messages of the same type in an interchange.

Turns off this caching mechanism, saving memory but costing time.

# File lib/edi4r/diagrams.rb, line 72
def Diagram.caching_off
  @@caching = false
end
caching_on() click to toggle source

Turns on caching (default setting), saving time but costing memory.

# File lib/edi4r/diagrams.rb, line 78
def Diagram.caching_on
  @@caching = true
end
create( std, params ) click to toggle source

Creates (and caches) a new diagram. Returns reference to existing diagram when already in cache.

std

The syntax standard key. Currently supported:

  • ‘E’ (EDIFACT),

  • ‘I’ (SAP IDOC)

  • ‘S’ (SEDAS, experimental)

  • ‘A’ (ANSI X.12, limited)

params

A hash of parameters that uniquely identify the selected diagram. Internal use only - see source code for details.

# File lib/edi4r/diagrams.rb, line 105
def Diagram.create( std, params )
  case std
  when 'E' # UN/EDIFACT
    par = {
      :d0051 => 'UN', 
      :d0057 => nil,
      :is_iedi => false }.update( params )
  when 'I' # SAP IDocs
    par = params
    #      raise "Not implemented yet!"
  when 'S' # SEDAS
    par = params
  when 'A' # ANSI X12
    par = params
  else
    raise "Unsupported syntax standard: #{std}"
  end

  if Diagram.caching?
    #
    # Use param set as key for caching
    #
    key = par.sort {|a,b| a.to_s <=> b.to_s}.hash
    obj = @@cache[key]
    return obj unless obj.nil?

    obj = new( std, par )
    @@cache[key] = obj # cache & return it

  else
    new( std, par )
  end
end
flush_cache() click to toggle source

Releases memory by flushing the cache. Needed primarily for unit tests, where many if not all available diagrams are created.

# File lib/edi4r/diagrams.rb, line 91
def Diagram.flush_cache
  @@cache = {}
end

Public Instance Methods

[](i) click to toggle source

Index access through ordinal number of node, starting with 1 (!).

# File lib/edi4r/diagrams.rb, line 228
def [](i)
  @node_dict[i] # efficient access via hash
end
branch() click to toggle source

Returns the top branch of the diagram.

# File lib/edi4r/diagrams.rb, line 240
def branch
  @diag
end
dir() click to toggle source

Getter for the directory object associated with this diagram.

# File lib/edi4r/diagrams.rb, line 234
def dir
  @dir
end
each(&b) click to toggle source

Iterates recursively through all nodes of the diagram.

# File lib/edi4r/diagrams.rb, line 221
def each(&b)
  @diag.each(&b)
end