Browse Source

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]
dev
Andy Meneely 9 years ago
parent
commit
3ce5d8b4eb
  1. 10
      lib/squib/import/data_frame.rb
  2. 8
      spec/import/data_frame_spec.rb

10
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}/).
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
concat(" |\n")
lstrip # initially no whitespace next to key
return new_str + " |\n"
end
def def_column(col)

8
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

Loading…
Cancel
Save