lib/x12/field.rb in pd_x12-1.4.4 vs lib/x12/field.rb in pd_x12-1.4.5
- old
+ new
@@ -1,11 +1,11 @@
#--
# This file is part of the X12Parser library that provides tools to
# manipulate X12 messages using Ruby native syntax.
#
-# http://x12parser.rubyforge.org
-#
+# http://x12parser.rubyforge.org
+#
# Copyright (C) 2008 APP Design, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
@@ -31,15 +31,15 @@
attr_reader :name, :type, :required, :min_length, :max_length, :validation
attr_writer :content
# Create a new field with given parameters
def initialize(name, type, required, min_length, max_length, validation)
- @name = name
- @type = type
+ @name = name
+ @type = type
@required = required
@min_length = min_length.to_i
- @max_length = max_length.to_i
+ @max_length = max_length.to_i
@validation = validation
@content = nil
end
# Returns printable string with field's content
@@ -54,10 +54,12 @@
def render
unless @content
@content = $1 if self.type =~ /"(.*)"/ # If it's a constant
end
- @content || ''
+ rendered = @content || ''
+ rendered = rendered.ljust(@min_length) if @required
+ rendered
end # render
# Check if it's been set yet and it's not a constant
def has_content?
!@content.nil? && ('"'+@content+'"' != self.type)