lib/edi4r.rb
# Here we perform the "magic" that provides us with dynamically
# "generated" getters and setters for just those DE and CDE
# available in the given Collection_S instance.
#
# UN/EDIFACT examples:
#  d3055, d1004=(value), cC105, a7174[1].value
Here we perform the "magic" that provides us with dynamically
"generated" getters and setters for just those DE and CDE
available in the given Collection_S instance.


Here we perform the " magic " that provides us with dynamically " generated " getters and setters for just those DE and CDE available in the given Collection_S instance .
def method_missing(sym, *par)
      if sym.id2name =~ /^([acds])(\w+)(=)?/
        rc = lookup($2)
        if rc.is_a? Array
          if rc.size==1
            rc = rc.first
          elsif rc.size==0
            return super
          end
        end
        if $3
          raise TypeError, "Can't assign to array #$2" if rc.is_a? Array
          raise TypeError, "Can only assign to a DE value" if $1 != 'd'
          rc.value = par[0]
        else
          return rc.value if rc.is_a? DE and $1 == 'd'
          return rc if rc.is_a? CDE      and $1 == 'c'
          return rc if rc.is_a? Segment  and $1 == 's'
          err_msg =  "Method prefix '#$1' not matching result '#{rc.class}'!"
          raise TypeError, err_msg unless rc.is_a? Array
          rc.freeze
          return rc if $1 == 'a'
          raise TypeError,"Array found - use 'a#$2[i]' to access component i"
        end
      else
        super
      end
    end
def method_missing ( sym , * par ) if sym . id2name =~ / ^([acds])( \w +)(=)? / rc = lookup ( $2 ) if rc . is_a? Array if rc . size == 1 rc = rc . first elsif rc . size == 0 return super end end if $3 raise TypeError , "Can't assign to array #$2" if rc . is_a? Array raise TypeError , "Can only assign to a DE value" if $1 != 'd' rc . value = par [ 0 ] else return rc . value if rc . is_a? DE and $1 == 'd' return rc if rc . is_a? CDE and $1 == 'c' return rc if rc . is_a? Segment and $1 == 's' err_msg = "Method prefix '#$1' not matching result '#{rc.class}'!" raise TypeError , err_msg unless rc . is_a? Array rc . freeze return rc if $1 == 'a' raise TypeError , "Array found - use 'a#$2[i]' to access component i" end else super end end
Here we perform the "magic" that provides us with dynamically
"generated" getters and setters for just those DE and CDE
available in the given Collection_S instance.
Here we perform the " magic " that provides us with dynamically " generated " getters and setters for just those DE and CDE available in the given Collection_S instance .
# Setter # Getter # Don't let whole DEs be overwritten - enforce usage of "value":
sym
par