Permalink
Browse files

Fixes issue #9

Adds Spreadsheet::Excel::Row#to_a method to properly decode Date and
DateTime data.
  • Loading branch information...
1 parent 878103e commit f2d38c3018ed79bd1082fdfb88fdddbdedc5c9b2 @mdgreenfield committed Oct 6, 2012
Showing with 11 additions and 0 deletions.
  1. +6 −0 lib/spreadsheet/excel/row.rb
  2. +5 −0 test/excel/row.rb
@@ -42,6 +42,12 @@ def [] idx, len=nil
enriched_data idx, at(idx)
end
end
+ ##
+ # Returns data as an array. If a cell is formatted as a Date or DateTime, the
+ # decoded Date or DateTime value is returned.
+ def to_a
+ self[0...length]
+ end
private
def _date data # :nodoc:
return data if data.is_a?(Date)
View
@@ -18,6 +18,11 @@ def test_date
row = Row.new @worksheet, 0, [nil, 27627.6789]
assert_equal Date.new(1975,8,21), row.date(1)
end
+ def test_to_a
+ row = Row.new @worksheet, 0, [nil, 1, 27627.6789]
+ row.set_format(2, Format.new(:number_format => 'DD.MM.YYYY'))
+ assert_equal [nil, 1, Date.new(1975, 8, 21)], row.to_a
+ end
def test_datetime
row = Row.new @worksheet, 0, [nil, 27627.765]
d1 = DateTime.new(1975,8,21) + 0.765

0 comments on commit f2d38c3

Please sign in to comment.