lib/io_streams/tabular/parser/fixed.rb in iostreams-1.1.0 vs lib/io_streams/tabular/parser/fixed.rb in iostreams-1.1.1
- old
+ new
@@ -21,11 +21,11 @@
# Returns [String] fixed layout values extracted from the supplied hash.
# String will be encoded to `encoding`
def render(row, header)
hash = header.to_hash(row)
- result = ''
+ result = ""
fixed_layout.each do |map|
# A nil value is considered an empty string
value = hash[map.key].to_s
result << format("%-#{map.size}.#{map.size}s", value)
end
@@ -40,12 +40,12 @@
end
hash = {}
index = 0
fixed_layout.each do |map|
- value = line[index..(index + map.size - 1)]
- index += map.size
+ value = line[index..(index + map.size - 1)]
+ index += map.size
hash[map.key] = value.to_s.strip
end
hash
end
@@ -58,9 +58,10 @@
def parse_layout(layout)
layout.collect do |map|
size = map[:size]
key = map[:key]
raise(ArgumentError, "Missing required :key and :size in: #{map.inspect}") unless size && key
+
FixedLayout.new(key, size)
end
end
end
end