lib/edi4r.rb
# Performs various validation checks and returns the number of
# issues found (plus the value of +err_count+):
#
# - empty while mandatory?
# - character set limitations violated?
# - various format restrictions violated?
Performs various validation checks and returns the number of
issues found (plus the value of +err_count+).

empty while mandatory.
character set limitations violated.
Performs various validation checks and returns the number of issues found ( plus the value of + err_count + ) . empty while mandatory . character set limitations violated .
def validate( err_count=0 )
      location = "DE {parent.name}/{@name}"
      if empty?
        if required?
          warn "{location}: Empty though mandatory!"
          err_count += 1
        end
      else
         Charset check
        if (pos = (value =~ root.illegal_charset_pattern)) != nil
          warn "{location}: Illegal character: {value[pos].chr}"
          err_count += 1
        end
         Format check, raise error if not consistent!
        if @format =~ /^(a|n|an)(..)?(\d+)$/
          _a_n_an, _upto, _size = $1, $2, $3
          case _a_n_an
          when 'n'
            strval = value.to_s
            re = Regexp.new('^(-)?(\d+)([.,]\d+)?$')
            md = re.match strval
            if md.nil?
              raise "{location}: '{strval}' - not matching format @format"
              warn "{strval} - not matching format @format"
              err_count += 1
            end
            len = strval.length
             Sign char does not go into length count:
            len -= 1 if md[1]=='-'
             Decimal char does not go into length count:
            len -= 1 if not md[3].nil?
             len -= 1 if (md[1]=='-' and md[3]) || (md[1] != '' and not md[3])
            break if not required? and len == 0
            if len > _size.to_i
            if _upto.nil? and len != _size.to_i or len > _size.to_i
              warn "Context in {location}: {_a_n_an}, {_upto}, {_size}; {md[1]}, {md[2]}, {md[3]}"
              warn "Length  mismatch in {location}: {len} vs. {_size}"
              err_count += 1
                          warn "  (strval was: '{strval}')"
            end
            if md[1] =~/^0+/
              warn "{strval} contains leading zeroes"
              err_count += 1
            end
            if md[3] and md[3]=~ /.0+$/
              warn "{strval} contains trailing decimal sign/zeroes"
              err_count += 1
            end
          when 'a', 'an'
            len = value.is_a?(Numeric) ? value.to_s.length : value.length
            len = value.to_s.length
            if _upto.nil? and len != $3.to_i or len > $3.to_i
              warn "Length mismatch in {location}: {len} vs. {_size}"
              err_count += 1
            end
          else
            raise "{location}: Illegal format prefix {_a_n_an}"
             err_count += 1
          end
        else
          warn "{location}: Illegal format: {@format}!"
          err_count += 1
        end
      end
      err_count
    end
def validate ( err_count = 0 ) location = "DE #{parent.name}/#{@name}" if empty? if required? warn "#{location}: Empty though mandatory!" err_count += 1 end else if ( pos = ( value =~ root . illegal_charset_pattern ) ) warn "#{location}: Illegal character: #{value[pos].chr}" err_count += 1 end if @format =~ / ^(a|n|an)(..)?( \d +)$ / _a_n_an , _upto , _size = $1 , $2 , $3 case _a_n_an when 'n' strval = value . to_s re = Regexp . new ( '^(-)?(\d+)([.,]\d+)?$' ) md = re . match strval if md . nil? raise "#{location}: '#{strval}' - not matching format #@format" end len = strval . length len -= 1 if md [ 1 ] == '-' len -= 1 if not md [ 3 ] . nil? break if not required? and len == 0 if len > _size . to_i warn "Context in #{location}: #{_a_n_an}, #{_upto}, #{_size}; #{md[1]}, #{md[2]}, #{md[3]}" warn "Length # mismatch in #{location}: #{len} vs. #{_size}" err_count += 1 end if md [ 1 ] =~ / ^0+ / warn "#{strval} contains leading zeroes" err_count += 1 end if md [ 3 ] and md [ 3 ] =~ / .0+$ / warn "#{strval} contains trailing decimal sign/zeroes" err_count += 1 end when 'a' , 'an' len = value . to_s . length if _upto . nil? and len != $3 . to_i or len > $3 . to_i warn "Length mismatch in #{location}: #{len} vs. #{_size}" err_count += 1 end else raise "#{location}: Illegal format prefix #{_a_n_an}" end else warn "#{location}: Illegal format: #{@format}!" err_count += 1 end end err_count end
Performs various validation checks and returns the number of
issues found (plus the value of +err_count+):
Performs various validation checks and returns the number of issues found ( plus the value of + err_count + ) :
# # Charset check # # != nil # # Format check, raise error if not consistent! # #              warn "#{strval} - not matching format #@format" #              err_count += 1 # Sign char does not go into length count: # Decimal char does not go into length count: # len -= 1 if (md[1]=='-' and md[3]) || (md[1] != '' and not md[3]) #            if _upto.nil? and len != _size.to_i or len > _size.to_i #            warn "  (strval was: '#{strval}')" #            len = value.is_a?(Numeric) ? value.to_s.length : value.length # err_count += 1
err_count