-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
This code should do it...
# Fixedwidth.generate(data: input, header: header, start: start, stop: stop, delimiter: "|") do |line|
# output << line
# end
module Fixedwidth
def self.generate(options)
@options = options
@options[:delimiter] ||= ","
@options[:data].each do |hash|
string = " " * (string_length*2) # FIXME: Find of end of line!
hash.sort_by { |k,v| header_positions["#{k}"][0] }.each do |k,v|
positions = header_positions["#{k}"]
string[positions[0],positions[1]]="#{v}"
end
yield(string)
end
end
def self.string_length
column_positions.last.inject(0) { |i,sum| sum += i }
end
def self.header_positions
@header_positions ||= {}.tap do |positions|
start.zip(stop).each_with_index do |item,index|
a, b = item[0].to_i, item[1].to_i
a = a - 1
b = b-a
positions.merge!(header[index] => [a,b])
end
end
end
endMetadata
Metadata
Assignees
Labels
No labels