csv-hash 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{csv-hash}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tal Atlas"]
@@ -11,15 +11,15 @@ module CSVHash
11
11
  FasterCSV.foreach(file) do |row|
12
12
  num += 1
13
13
  if num == 1
14
- columns = row.collect {|c| c.strip}
14
+ columns = row.collect {|c| c.strip if c}
15
15
  next
16
16
  end
17
17
 
18
18
  hash = {}
19
19
  columns.each_with_index do |col, i|
20
20
  next unless col
21
- col = col.strip
22
- val = row[i].strip
21
+ col = col ? col.strip : nil
22
+ val = row[i] ? row[i].strip : nil
23
23
 
24
24
  setter = hash
25
25
  sp = col.split('__')
@@ -38,7 +38,7 @@ module CSVHash
38
38
  data << hash
39
39
  end
40
40
 
41
- return data, columns
41
+ return data, columns.compact
42
42
  end
43
43
 
44
44
  def to_string hashes, columns
@@ -1,3 +1,3 @@
1
- one,two,foo__bar__three,foo__bar__four,foo__five,bar__six,bar__seven
2
- 1,2,3,4,5,6,7
3
- 14,13,12,11,10,9,8
1
+ one,two,foo__bar__three,foo__bar__four,foo__five,bar__six,nil,bar__seven
2
+ 1,2,3,4,5,6,,7
3
+ 14,13,12,11,10,9,,8
@@ -1,3 +1,3 @@
1
- one,two,foo__bar__three,foo__bar__four, foo__five,bar__six,bar__seven
2
- 1,2,3,4,5, 6,7
3
- 14,13,12,11,10,9,8
1
+ one,two,foo__bar__three,foo__bar__four, foo__five,bar__six,nil,,bar__seven
2
+ 1,2,3,4,5, 6,,,7
3
+ 14,13,12,11,10,9,,,8
@@ -12,7 +12,7 @@ describe CSVHash do
12
12
  end
13
13
 
14
14
  it "should get correct column names (no spaces)" do
15
- @columns.should == "one,two,foo__bar__three,foo__bar__four,foo__five,bar__six,bar__seven".split(',')
15
+ @columns.should == ["one", "two", "foo__bar__three", "foo__bar__four", "foo__five", "bar__six", "nil", "bar__seven"]
16
16
  end
17
17
 
18
18
  it "should only include data rows" do
@@ -27,7 +27,8 @@ describe CSVHash do
27
27
  "bar" => {"three" => "3", "four" => "4"},
28
28
  "five" => "5"
29
29
  },
30
- "bar" => {"six" => "6", "seven" => "7"}
30
+ "bar" => {"six" => "6", "seven" => "7"},
31
+ "nil" => nil
31
32
  }
32
33
  @array.first.should == first
33
34
 
@@ -38,14 +39,20 @@ describe CSVHash do
38
39
  "bar" => {"three" => "12", "four" => "11"},
39
40
  "five" => "10"
40
41
  },
41
- "bar" => {"six" => "9", "seven" => "8"}
42
+ "bar" => {"six" => "9", "seven" => "8"},
43
+ "nil" => nil
42
44
  }
43
45
  @array.last.should == second
44
46
  end
45
47
  end
46
48
 
47
49
 
48
- it "should do a round trip" do
50
+ it "should generate an expected file" do
49
51
  CSVHash.to_string(*CSVHash.from_file(@csv_path)).chomp.should == File.open(@clean_csv_path).read.chomp
50
52
  end
53
+
54
+ it "should do a round trip" do
55
+ pending "Desire to add nil columns"
56
+ CSVHash.to_string(*CSVHash.from_file(@csv_path)).chomp.should == File.open(@csv_path).read.chomp
57
+ end
51
58
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tal Atlas