spreadsheet 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.7.4 / 06.10.2012
2
+
3
+ * Adds Spreadsheet::Excel::Row#to_a method to properly decode Date and DateTime data.
4
+ * patches by https://github.com/mdgreenfield/spreadsheet
5
+
1
6
  === 0.7.3 / 26.06.2012
2
7
 
3
8
  * Fix Format borders
data/Manifest.txt CHANGED
@@ -44,14 +44,15 @@ lib/spreadsheet/workbook.rb
44
44
  lib/spreadsheet/worksheet.rb
45
45
  lib/spreadsheet/writer.rb
46
46
  spreadsheet.gemspec
47
+ test/data/test_borders.xls
47
48
  test/data/test_changes.xls
48
49
  test/data/test_copy.xls
49
50
  test/data/test_datetime.xls
50
51
  test/data/test_empty.xls
51
52
  test/data/test_formula.xls
52
53
  test/data/test_long_sst_record.xls
53
- test/data/test_merged_cells.xls
54
54
  test/data/test_merged_and_protected.xls
55
+ test/data/test_merged_cells.xls
55
56
  test/data/test_missing_row.xls
56
57
  test/data/test_version_excel5.xls
57
58
  test/data/test_version_excel95.xls
@@ -61,9 +62,10 @@ test/excel/row.rb
61
62
  test/excel/writer/workbook.rb
62
63
  test/excel/writer/worksheet.rb
63
64
  test/font.rb
65
+ test/format.rb
64
66
  test/integration.rb
65
67
  test/row.rb
66
68
  test/suite.rb
67
69
  test/workbook.rb
68
- test/worksheet.rb
69
70
  test/workbook_protection.rb
71
+ test/worksheet.rb
@@ -42,6 +42,12 @@ class Row < Spreadsheet::Row
42
42
  enriched_data idx, at(idx)
43
43
  end
44
44
  end
45
+ ##
46
+ # Returns data as an array. If a cell is formatted as a Date or DateTime, the
47
+ # decoded Date or DateTime value is returned.
48
+ def to_a
49
+ self[0...length]
50
+ end
45
51
  private
46
52
  def _date data # :nodoc:
47
53
  return data if data.is_a?(Date)
data/lib/spreadsheet.rb CHANGED
@@ -42,7 +42,7 @@ module Spreadsheet
42
42
 
43
43
  ##
44
44
  # The version of Spreadsheet you are using.
45
- VERSION = '0.7.3'
45
+ VERSION = '0.7.4'
46
46
 
47
47
  ##
48
48
  # Default client Encoding. Change this value if your application uses a
Binary file
data/test/excel/row.rb CHANGED
@@ -18,6 +18,11 @@ class TestRow < Test::Unit::TestCase
18
18
  row = Row.new @worksheet, 0, [nil, 27627.6789]
19
19
  assert_equal Date.new(1975,8,21), row.date(1)
20
20
  end
21
+ def test_to_a
22
+ row = Row.new @worksheet, 0, [nil, 1, 27627.6789]
23
+ row.set_format(2, Format.new(:number_format => 'DD.MM.YYYY'))
24
+ assert_equal [nil, 1, Date.new(1975, 8, 21)], row.to_a
25
+ end
21
26
  def test_datetime
22
27
  row = Row.new @worksheet, 0, [nil, 27627.765]
23
28
  d1 = DateTime.new(1975,8,21) + 0.765
data/test/format.rb ADDED
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env ruby
2
+ # TestFormat -- Spreadsheet -- 06.11.2012 -- mina.git@naguib.ca
3
+
4
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
5
+
6
+ require 'test/unit'
7
+ require 'spreadsheet'
8
+
9
+ module Spreadsheet
10
+ class TestFormat < Test::Unit::TestCase
11
+ def setup
12
+ @format = Format.new
13
+ end
14
+ def test_date?
15
+ assert_equal false, @format.date?
16
+ @format.number_format = "hms"
17
+ assert_equal false, @format.date?
18
+ @format.number_format = "Y"
19
+ assert_equal true, @format.date?
20
+ @format.number_format = "YMD"
21
+ assert_equal true, @format.date?
22
+ end
23
+ def test_date_or_time?
24
+ assert_equal false, @format.date_or_time?
25
+ @format.number_format = "hms"
26
+ assert_equal true, @format.date_or_time?
27
+ @format.number_format = "YMD"
28
+ assert_equal true, @format.date_or_time?
29
+ @format.number_format = "hmsYMD"
30
+ assert_equal true, @format.date_or_time?
31
+ end
32
+ def test_datetime?
33
+ assert_equal false, @format.datetime?
34
+ @format.number_format = "H"
35
+ assert_equal false, @format.datetime?
36
+ @format.number_format = "S"
37
+ assert_equal false, @format.datetime?
38
+ @format.number_format = "Y"
39
+ assert_equal false, @format.datetime?
40
+ @format.number_format = "HSYMD"
41
+ assert_equal true, @format.datetime?
42
+ end
43
+ def test_time?
44
+ assert_equal false, @format.time?
45
+ @format.number_format = "YMD"
46
+ assert_equal false, @format.time?
47
+ @format.number_format = "hmsYMD"
48
+ assert_equal true, @format.time?
49
+ @format.number_format = "h"
50
+ assert_equal true, @format.time?
51
+ @format.number_format = "hm"
52
+ assert_equal true, @format.time?
53
+ @format.number_format = "hms"
54
+ assert_equal true, @format.time?
55
+ end
56
+ def test_borders?
57
+ assert_equal [:none, :none, :none, :none], @format.border
58
+ @format.border = :thick
59
+ assert_equal [:thick, :thick, :thick, :thick], @format.border
60
+ @format.left = :hair
61
+ assert_equal [:thick, :thick, :thick, :hair], @format.border
62
+ @format.right = :hair
63
+ assert_equal [:thick, :thick, :hair, :hair], @format.border
64
+ @format.top = :hair
65
+ assert_equal [:thick, :hair, :hair, :hair], @format.border
66
+ @format.bottom = :hair
67
+ assert_equal [:hair, :hair, :hair, :hair], @format.border
68
+ assert_raises(ArgumentError) do
69
+ @format.bottom = :bogus
70
+ end
71
+ assert_equal [:black, :black, :black, :black], @format.border_color
72
+ @format.border_color = :green
73
+ assert_equal [:green, :green, :green, :green], @format.border_color
74
+ @format.left_color = :red
75
+ assert_equal [:green, :green, :green, :red], @format.border_color
76
+ @format.right_color = :red
77
+ assert_equal [:green, :green, :red, :red], @format.border_color
78
+ @format.top_color = :red
79
+ assert_equal [:green, :red, :red, :red], @format.border_color
80
+ @format.bottom_color = :red
81
+ assert_equal [:red, :red, :red, :red], @format.border_color
82
+ assert_raises(ArgumentError) do
83
+ @format.bottom_color = :bogus
84
+ end
85
+ end
86
+ end
87
+ end
data/test/integration.rb CHANGED
@@ -1233,6 +1233,37 @@ module Spreadsheet
1233
1233
  sheet[0,0] # trigger read_worksheet
1234
1234
  assert_equal [[2, 4, 1, 1], [3, 3, 2, 3]], sheet.merged_cells
1235
1235
  end
1236
+ def test_read_borders
1237
+ path = File.join @data, 'test_borders.xls'
1238
+ book = Spreadsheet.open path
1239
+ assert_instance_of Excel::Workbook, book
1240
+ sheet = book.worksheet 0
1241
+ format = sheet.row(0).format 0
1242
+ assert_equal :none, format.left
1243
+ assert_equal :thin, format.top
1244
+ assert_equal :medium, format.right
1245
+ assert_equal :thick, format.bottom
1246
+ assert_equal :builtin_black, format.left_color
1247
+ assert_equal :red, format.top_color
1248
+ assert_equal :green, format.right_color
1249
+ assert_equal :yellow, format.bottom_color
1250
+ end
1251
+ def test_write_borders
1252
+ book = Spreadsheet::Workbook.new
1253
+ path = File.join @var, 'test_write_borders.xls'
1254
+ sheet1 = book.create_worksheet
1255
+ (sheet1.row(0).format 0).border = :hair
1256
+ (sheet1.row(0).format 0).border_color = :brown
1257
+ assert_nothing_raised do
1258
+ book.write path
1259
+ end
1260
+ book2 = Spreadsheet.open path
1261
+ assert_instance_of Excel::Workbook, book2
1262
+ sheet2 = book2.worksheet 0
1263
+ format = sheet2.row(0).format 0
1264
+ assert_equal :hair, format.left
1265
+ assert_equal :brown, format.top_color
1266
+ end
1236
1267
 
1237
1268
  private
1238
1269
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreadsheet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 3
10
- version: 0.7.3
9
+ - 4
10
+ version: 0.7.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Masaomi Hatakeyama, Zeno R.R. Davatz
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-26 00:00:00 Z
18
+ date: 2012-10-06 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: ruby-ole
@@ -127,14 +127,15 @@ files:
127
127
  - lib/spreadsheet/worksheet.rb
128
128
  - lib/spreadsheet/writer.rb
129
129
  - spreadsheet.gemspec
130
+ - test/data/test_borders.xls
130
131
  - test/data/test_changes.xls
131
132
  - test/data/test_copy.xls
132
133
  - test/data/test_datetime.xls
133
134
  - test/data/test_empty.xls
134
135
  - test/data/test_formula.xls
135
136
  - test/data/test_long_sst_record.xls
136
- - test/data/test_merged_cells.xls
137
137
  - test/data/test_merged_and_protected.xls
138
+ - test/data/test_merged_cells.xls
138
139
  - test/data/test_missing_row.xls
139
140
  - test/data/test_version_excel5.xls
140
141
  - test/data/test_version_excel95.xls
@@ -144,12 +145,13 @@ files:
144
145
  - test/excel/writer/workbook.rb
145
146
  - test/excel/writer/worksheet.rb
146
147
  - test/font.rb
148
+ - test/format.rb
147
149
  - test/integration.rb
148
150
  - test/row.rb
149
151
  - test/suite.rb
150
152
  - test/workbook.rb
151
- - test/worksheet.rb
152
153
  - test/workbook_protection.rb
154
+ - test/worksheet.rb
153
155
  - .gemtest
154
156
  homepage: https://github.com/zdavatz/spreadsheet
155
157
  licenses: []