Sha256: 4889bf1608c686162f09938fd6ec80da5f4d575c9c70a398def2e857acc95115

Contents?: true

Size: 606 Bytes

Versions: 4

Compression:

Stored size: 606 Bytes

Contents

class FixedWidth
  class Generator

    def initialize(definition)
      @definition = definition
    end

    def generate(data)
      @builder = []
      @definition.sections.each do |section|
        content = data[section.name]
        arrayed_content = content.is_a?(Array) ? content : [content]
        raise FixedWidth::RequiredSectionEmptyError.new("Required section '#{section.name}' was empty.") if (content.nil? || content.empty?) && !section.optional
        arrayed_content.each {|row| @builder << section.format(row) }
      end
      @builder.join("\n")
    end

  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
fixed_width-multibyte-0.2.3 lib/fixed_width/generator.rb
fixed_width-multibyte-0.2.2 lib/fixed_width/generator.rb
fixed_width-0.2.1 lib/fixed_width/generator.rb
fixed_width-0.2.0 lib/fixed_width/generator.rb