From 3ce5d8b4eb3dc5f355c9f7568fb27d3cdd379702 Mon Sep 17 00:00:00 2001 From: Andy Meneely Date: Thu, 22 Dec 2016 11:22:40 -0500 Subject: [PATCH] data: fix wrap_n_pad bug This doesn't make modifications to the original string. If only Ruby used their own convention and did str#concat! instead of str#concat Fixes #191 [skip ci] --- lib/squib/import/data_frame.rb | 14 +++++++------- spec/import/data_frame_spec.rb | 8 ++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/squib/import/data_frame.rb b/lib/squib/import/data_frame.rb index cb34048..30ec576 100644 --- a/lib/squib/import/data_frame.rb +++ b/lib/squib/import/data_frame.rb @@ -86,13 +86,13 @@ module Squib end def wrap_n_pad(str, max_col) - str.to_s. - concat(' '). # handle nil & empty strings - scan(/.{1,34}/). - map { |s| (' ' * max_col) + " | " + s.ljust(34) }. - join(" |\n"). - lstrip. # initially no whitespace next to key - concat(" |\n") + new_str = str.to_s + ' ' # handle nil & empty strings + new_str = new_str. + scan(/.{1,34}/). # break down + map { |s| (' ' * max_col) + " | " + s.ljust(34) }. + join(" |\n"). + lstrip # initially no whitespace next to key + return new_str + " |\n" end def def_column(col) diff --git a/spec/import/data_frame_spec.rb b/spec/import/data_frame_spec.rb index 6f7bec5..22d72d8 100644 --- a/spec/import/data_frame_spec.rb +++ b/spec/import/data_frame_spec.rb @@ -246,6 +246,14 @@ Fun with UTF8! | 👊 | ╰------------------------------------╯ EOS end + + it 'does not pad the data' do + data = Squib::DataFrame.new + data['a'] = ['b', 'c'] + expect(data.to_pretty_text.size).to be > 0 + expect(data.columns).to eq ['a'] + expect(data['a']).to eq ['b', 'c'] + end end end