class EDI::S::DE
There are no CDEs in IDocs: class CDE_E < CDE
end
Public Class Methods
new( p, name, status, fmt )
click to toggle source
Calls superclass method
EDI::DE::new
# File lib/edi4r/sedas.rb, line 457 def initialize( p, name, status, fmt ) super( p, name, status, fmt ) fmt =~ /(a|an|n|d|t)(\.\.)?(\d+):(\d+)/ raise "Illegal format string in field #{name}: #{fmt}" if $3.nil? or $4.nil? @length, @offset = $3.to_i, $4.to_i-1 # puts "#{name}: len=#{@length.to_s}, off=#{@offset.to_s}" # check if supported format syntax # check if supported status value end
Public Instance Methods
parse( buf )
click to toggle source
# File lib/edi4r/sedas.rb, line 468 def parse( buf ) # Buffer contains segment line; extract sub-string! # msg = "DE #{@name}: Buffer missing or too short" if buf.nil? or buf.length < @offset# +@length @value = nil return end # Sure that "strip" is always ok, and that we can ignore whitespace?? # case @name # when 'SEGNUM' @value = buf[@offset...@offset+@length] if self.format[0]==?n # Numerical? if @value =~ /^ *$/ # Optional numerical field @value = nil return end code = @value[-1] @value[-1] = ?0 @value = @value.to_i if RUBY_VERSION >= '1.9' case code when ?A..?I @value += (code.ord-?@.ord) when ?J..?R @value += (code.ord-?I.ord) @value = -@value when ?}, "\x81", "\xfc" # ü (0xFC) to be confirmed @value = -@value when ?{, ?0, ' ' # Blank, ä to be confirmed # noop when ?1..?9 @value += (code.ord-?0.ord) else raise "#{self.name}: #{code} is not a valid last char of a numerical field" end else # older Ruby version case code when ?A..?I @value += (code-?@) when ?J..?R @value += (code-?I) @value = -@value when ?}, 0x81, 0xfc # ü (0xFC) to be confirmed @value = -@value when ?{, ?0, 0x20 # Blank, ä to be confirmed # noop when ?1..?9 @value += (code-?0) else raise "#{self.name}: #{code.chr} (#{code}) is not a valid last char of a numerical field" end end # Ruby version elsif @value.is_a? String @value.tr!(@@umlaute_cp850, @@umlaute_iso8859_1) @value.tr!(@@umlaute_iso636_de, @@umlaute_iso8859_1) end # else # @value = buf[@offset...@offset+@length].strip # end # @value = nil if @value =~ /^\s*$/ end
to_s()
click to toggle source
TODO: reversal of charset mapping, debugging (round-circle ok?)
# File lib/edi4r/sedas.rb, line 557 def to_s # return '' if empty? if self.format[0]==?n # Numerical? if @value && @value < 0 @value = -@value value_str = @value.to_s value_str[-1] = case value_str[-1] when '0' then '}' when '1' then 'J' when '2' then 'K' when '3' then 'L' when '4' then 'M' when '5' then 'N' when '6' then 'O' when '7' then 'P' when '8' then 'Q' when '9' then 'R' else raise "Illegal last digit in numeric value '#{value_str}'" end value_str.rjust(@length,'0')[0,@length] # left-padded with '0' else @value.to_s.rjust(@length,'0')[0,@length] # left-padded with '0' end else @value.to_s.ljust(@length)[0,@length] # right-padded with ' ' end end
validate( err_count=0 )
click to toggle source
Calls superclass method
EDI::DE#validate
# File lib/edi4r/sedas.rb, line 532 def validate( err_count=0 ) location = "#{parent.name} - #{@name}" @format =~ /((a|an|n|d|t)(\.\.)?(\d+)):\d+/ fmt = [$2, $3, $4].join case $1 when 'd8' if !empty? && value !~ /^\d{8}$/ warn "#{location}: Format \'#@format\' violated: #@value" err_count+=1 end when 't6' if !empty? && value !~ /^\d{6}$/ warn "#{location}: Format \'#@format\' violated: #@value" err_count+=1 end when /^[dt].*/ warn "validate in DE #@name: Format \'#@format\' not validated yet!" else return super( err_count, fmt ) end err_count end