Class: Xdt::Section

Inherits:
Object
  • Object
show all
Extended by:
SectionHandling
Defined in:
lib/xdt/xdt_sections.rb

Instance Method Summary collapse

Methods included from SectionHandling

define_section

Constructor Details

#initialize(type) {|_self| ... } ⇒ Section

Returns a new instance of Section.

Yields:

  • (_self)

Yield Parameters:

  • _self (Xdt::Section)

    the object that the method was called on



38
39
40
41
42
# File 'lib/xdt/xdt_sections.rb', line 38

def initialize(type)
  @type = type
  @fields = []
  yield self if block_given?
end

Instance Method Details

#field(*args) ⇒ Object



44
45
46
# File 'lib/xdt/xdt_sections.rb', line 44

def field(*args)
  @fields << Field.new(*args)
end

#lengthObject



48
49
50
# File 'lib/xdt/xdt_sections.rb', line 48

def length
  to_s.length
end

#to_sObject



52
53
54
55
56
57
58
59
60
# File 'lib/xdt/xdt_sections.rb', line 52

def to_s
  header_length = 27
  
  data = @fields.map { |field| field.to_s }.join
  header = Field.new("8000", '%04d' % @type.to_i).to_s + 
           Field.new("8100", '%05d' % (data.length + header_length) ).to_s
  
  header + data
end