Class X12::Field
In: lib/X12/Field.rb
Parent: Object

$Id: Field.rb 35 2008-11-13 18:33:44Z ikk $

Class to represent a segment field. Please note, it‘s not a descendant of Base.

Methods

has_content?   inspect   new   render   set_empty!   to_s  

Attributes

content  [W] 
max_length  [R] 
min_length  [R] 
name  [R] 
required  [R] 
type  [R] 
validation  [R] 

Public Class methods

Create a new field with given parameters

[Source]

    # File lib/X12/Field.rb, line 35
35:     def initialize(name, type, required, min_length, max_length, validation)
36:       @name       = name       
37:       @type       = type       
38:       @required   = required == 'R' ? true : false   
39:       @min_length = min_length.to_i
40:       @max_length = max_length.to_i 
41:       @validation = validation
42:       @content = nil
43:     end

Public Instance methods

Check if it‘s been set yet

[Source]

    # File lib/X12/Field.rb, line 61
61:     def has_content?
62:       !@content.nil?
63:     end

Returns printable string with field‘s content

[Source]

    # File lib/X12/Field.rb, line 46
46:     def inspect
47:       "Field #{name}|#{type}|#{required}|#{min_length}-#{max_length}|#{validation} <#{@content}>"
48:     end

[Source]

    # File lib/X12/Field.rb, line 55
55:     def render
56:       # FIXME - this is for debug only
57:       @content || ''
58:     end

Erase the content

[Source]

    # File lib/X12/Field.rb, line 66
66:     def set_empty!
67:       @content = nil
68:     end

Synonym for ‘render

[Source]

    # File lib/X12/Field.rb, line 51
51:     def to_s
52:       render
53:     end