simplexls 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -20,4 +20,4 @@ This gem builds HTML tables which makes easy import data into Excel, OpenOffice
20
20
  xls.add([[1,2,3], [4,5,6]])
21
21
  xls.add([ { :a => 1, :b => 2, :c => 3}, { :a => 4, :b => 5, :c => 6}])
22
22
 
23
- The `add` method will accept an array of arrays or an array of hashes. When hashes are used, it will attempt to extract the values from the `Hash` using the header values as keys (first trying as a `String` then again as a `Symbol`). Since the headers are enumerated, order is preseved.
23
+ The `add` method will accept an array of arrays or an array of hashes. When hashes are used, it will attempt to extract the values from the `Hash` using the header values as keys (first trying as a `Symbol` then again as a `String` if needed). Since the headers are enumerated, order is preseved.
data/lib/simplexls.rb CHANGED
@@ -23,10 +23,14 @@ class SimpleXLS
23
23
  # TODO test this!
24
24
  def add(collection)
25
25
  collection.each do |obj|
26
- self << (Hash === obj ? headers.map { |key| obj[key] || obj[key.to_sym] } : obj.to_a)
26
+ self << (Hash === obj ? headers.map { |key| obj[key.to_sym] || obj[key.to_s] } : obj.to_a)
27
27
  end
28
28
  end
29
29
 
30
+ def inspect
31
+ "#<#{self.class}:0x#{object_id} headers=#{@headers.inspect}>"
32
+ end
33
+
30
34
  def to_s
31
35
  output = "<table><thead><tr>"
32
36
  output << @headers.collect { |hr| "<th>#{hr}</th>" }.join << "</tr></thead><tbody>"
@@ -62,18 +62,18 @@ class SimpleXlsTest < Test::Unit::TestCase
62
62
 
63
63
  def test_add_collection_with_hash
64
64
  xls = SimpleXLS.new(['a', 'b', 'c'])
65
-
66
65
  rows = [{:a => 1, :b => 2, :c => 3}, {:a => 4, :b => 5, :d => 7}]
67
66
  xls.add(rows)
68
67
 
69
68
  assert_equal rows.first.values, xls.rows.first
70
69
  assert_equal [4,5,nil], xls.rows.last
71
70
 
71
+ xls = SimpleXLS.new([:a, :b, :c])
72
72
  rows = [{:a => 1, :b => 2, :c => 3}, {:a => 4, :c => 5, :d => 7}]
73
73
  xls.add(rows)
74
74
 
75
75
  assert_equal rows.first.values, xls.rows.first
76
- assert_equal [4,nil,5], xls.rows.last
76
+ assert_equal [4,nil,5], xls.rows.last
77
77
  end
78
78
 
79
79
  def test_output
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplexls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: