Class: Xdt::Section
- Inherits:
-
Object
- Object
- Xdt::Section
- Extended by:
- SectionHandling
- Defined in:
- lib/xdt/xdt_sections.rb
Instance Method Summary collapse
- #field(*args) ⇒ Object
-
#initialize(type) {|_self| ... } ⇒ Section
constructor
A new instance of Section.
- #length ⇒ Object
- #to_s ⇒ Object
Methods included from SectionHandling
Constructor Details
#initialize(type) {|_self| ... } ⇒ Section
Returns a new instance of Section.
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 |
#length ⇒ Object
48 49 50 |
# File 'lib/xdt/xdt_sections.rb', line 48 def length to_s.length end |
#to_s ⇒ Object
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 |