workbook 0.4.8 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/workbook/version.rb +1 -1
- data/lib/workbook/writers/xlsx_writer.rb +9 -50
- data/test/helper.rb +2 -1
- data/test/test_book.rb +3 -3
- data/test/test_cell.rb +2 -2
- data/test/test_column.rb +4 -4
- data/test/test_format.rb +1 -1
- data/test/test_functional.rb +1 -1
- data/test/test_modules_cache.rb +1 -1
- data/test/test_modules_table_diff_sort.rb +2 -2
- data/test/test_modules_type_parser.rb +2 -2
- data/test/test_readers_csv_reader.rb +1 -1
- data/test/test_readers_ods_reader.rb +1 -1
- data/test/test_readers_txt_reader.rb +1 -1
- data/test/test_readers_xls_reader.rb +1 -1
- data/test/test_readers_xlsx_reader.rb +1 -1
- data/test/test_row.rb +3 -3
- data/test/test_sheet.rb +1 -1
- data/test/test_table.rb +2 -2
- data/test/test_template.rb +1 -1
- data/test/test_writers_html_writer.rb +1 -1
- data/test/test_writers_json_writer.rb +1 -1
- data/test/test_writers_xls_writer.rb +1 -1
- data/test/test_writers_xlsx_writer.rb +1 -1
- data/workbook.gemspec +2 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4b33014d1a79259654ae669373a886007f494f5
|
4
|
+
data.tar.gz: 6385dfbbe2965a2d4b59aa597ad9875040aa5226
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2f9ee0754579c29154b399ab4e868bc1a784b71f8cb61487606210ee3fb2b948b72d1182576071945e14574b7b99b087ef36f927d577a2add013546f280991f
|
7
|
+
data.tar.gz: 5797ba6fa5d14e6259a6a33ab45d1b228afae3eb9c99a8a2633856821978846f3e93f6e98173a085ee00bdf66b8ffff00b9f5411510f2aca981fede53ba1a3bc
|
data/lib/workbook/version.rb
CHANGED
@@ -6,7 +6,7 @@ module Workbook
|
|
6
6
|
module Writers
|
7
7
|
module XlsxWriter
|
8
8
|
|
9
|
-
# Generates an
|
9
|
+
# Generates an RubyXL doc, ready for export to XLSX
|
10
10
|
#
|
11
11
|
# @param [Hash] options A hash with options (unused so far)
|
12
12
|
# @return [Spreadsheet] A Spreadsheet object, ready for writing or more lower level operations
|
@@ -37,59 +37,18 @@ module Workbook
|
|
37
37
|
book
|
38
38
|
end
|
39
39
|
|
40
|
-
#
|
41
|
-
# #
|
42
|
-
# # @param [Workbook::Format, Hash] f A Workbook::Format or hash with format-options (:font_weight, :rotation, :background_color, :number_format, :text_direction, :color, :font_family)
|
43
|
-
# # @return [Spreadsheet::Format] A Spreadsheet format-object, ready for writing or more lower level operations
|
44
|
-
# def format_to_xlsx_format f
|
45
|
-
# xlsfmt = nil
|
46
|
-
# unless f.is_a? Workbook::Format
|
47
|
-
# f = Workbook::Format.new f
|
48
|
-
# end
|
49
|
-
# xlsfmt = f.return_raw_for Spreadsheet::Format
|
50
|
-
# unless xlsfmt
|
51
|
-
# xlsfmt=Spreadsheet::Format.new :weight=>f[:font_weight]
|
52
|
-
# xlsfmt.rotation = f[:rotation] if f[:rotation]
|
53
|
-
# xlsfmt.pattern_fg_color = html_color_to_xls_color(f[:background_color]) if html_color_to_xls_color(f[:background_color])
|
54
|
-
# xlsfmt.pattern = 1 if html_color_to_xls_color(f[:background_color])
|
55
|
-
# xlsfmt.number_format = strftime_to_ms_format(f[:number_format]) if f[:number_format]
|
56
|
-
# xlsfmt.text_direction = f[:text_direction] if f[:text_direction]
|
57
|
-
# xlsfmt.font.name = f[:font_family].split.first if f[:font_family]
|
58
|
-
# xlsfmt.font.family = parse_font_family(f) if f[:font_family]
|
59
|
-
# color = html_color_to_xls_color(f[:color])
|
60
|
-
# xlsfmt.font.color = color if color
|
61
|
-
# f.add_raw xlsfmt
|
62
|
-
# end
|
63
|
-
# return xlsfmt
|
64
|
-
# end
|
65
|
-
#
|
66
|
-
# # Parses right font-family name
|
67
|
-
# #
|
68
|
-
# # @param [Workbook::Format, hash] format to parse
|
69
|
-
# def parse_font_family(format)
|
70
|
-
# font = format[:font_family].to_s.split.last
|
71
|
-
# valid_values = [:none,:roman,:swiss,:modern,:script,:decorative]
|
72
|
-
# if valid_values.include?(font)
|
73
|
-
# return font
|
74
|
-
# elsif valid_values.include?(font.to_s.downcase.to_sym)
|
75
|
-
# return font.to_s.downcase.to_sym
|
76
|
-
# else
|
77
|
-
# font = font.to_s.downcase.strip
|
78
|
-
# translation = {
|
79
|
-
# "arial"=>:swiss,
|
80
|
-
# "times"=>:roman,
|
81
|
-
# "times new roman"=>:roman
|
82
|
-
# }
|
83
|
-
# tfont = translation[font]
|
84
|
-
# return tfont ? tfont : :none
|
85
|
-
# end
|
86
|
-
# end
|
40
|
+
# Generates an RubyXL doc, ready for export to XLSX
|
87
41
|
#
|
42
|
+
# @param [Hash] options A hash with options (unused so far)
|
43
|
+
# @return [String] A string, ready for streaming, e.g. `send_data workbook.stream_xlsx`
|
44
|
+
def stream_xlsx options = {}
|
45
|
+
to_xlsx(options).stream.string
|
46
|
+
end
|
88
47
|
|
89
|
-
# Write the current workbook to Microsoft Excel format (using the
|
48
|
+
# Write the current workbook to Microsoft Excel's new format (using the RubyXL gem)
|
90
49
|
#
|
91
50
|
# @param [String] filename
|
92
|
-
# @param [Hash] options see #
|
51
|
+
# @param [Hash] options see #to_xlsx
|
93
52
|
def write_to_xlsx filename="#{title}.xlsx", options={}
|
94
53
|
if to_xlsx(options).write(filename)
|
95
54
|
return filename
|
data/test/helper.rb
CHANGED
data/test/test_book.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
3
3
|
|
4
|
-
class TestWorkbook < Test
|
4
|
+
class TestWorkbook < Minitest::Test
|
5
5
|
def test_sheets
|
6
6
|
w = Workbook::Book.new nil
|
7
7
|
w.push
|
@@ -31,7 +31,7 @@ class TestWorkbook < Test::Unit::TestCase
|
|
31
31
|
w = Workbook::Book.new nil
|
32
32
|
s = Workbook::Sheet.new [Workbook::Row.new(Workbook::Table.new)]
|
33
33
|
assert_equal(w.sheet.class,Workbook::Sheet)
|
34
|
-
|
34
|
+
refute_equal(w.sheet, s)
|
35
35
|
w = Workbook::Book.new s
|
36
36
|
assert_equal(w.sheet, s)
|
37
37
|
end
|
@@ -41,7 +41,7 @@ class TestWorkbook < Test::Unit::TestCase
|
|
41
41
|
def test_template
|
42
42
|
b = Workbook::Book.new
|
43
43
|
raw = "asdf"
|
44
|
-
|
44
|
+
assert_raises(ArgumentError) { b.template = raw }
|
45
45
|
raw = Workbook::Template.new
|
46
46
|
b.template = raw
|
47
47
|
|
data/test/test_cell.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
3
3
|
|
4
|
-
class TestCell < Test
|
4
|
+
class TestCell < Minitest::Test
|
5
5
|
|
6
6
|
|
7
7
|
def test_init
|
@@ -10,7 +10,7 @@ class TestCell < Test::Unit::TestCase
|
|
10
10
|
w = Workbook::Cell.new "asdf"
|
11
11
|
assert_equal("asdf",w.value)
|
12
12
|
|
13
|
-
|
13
|
+
assert_raises(ArgumentError) { w = Workbook::Cell.new Workbook::Row }
|
14
14
|
|
15
15
|
t = Time.now
|
16
16
|
w = Workbook::Cell.new t
|
data/test/test_column.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
3
3
|
|
4
|
-
class TestColumn < Test
|
4
|
+
class TestColumn < Minitest::Test
|
5
5
|
|
6
6
|
def test_init
|
7
7
|
c = Workbook::Column.new
|
@@ -11,14 +11,14 @@ class TestColumn < Test::Unit::TestCase
|
|
11
11
|
assert_equal(20, c.limit)
|
12
12
|
assert_equal(Workbook::Cell.new("asdf"), c.default)
|
13
13
|
assert_equal(:boolean, c.column_type)
|
14
|
-
|
15
|
-
|
14
|
+
assert_raises(ArgumentError) { Workbook::Column.new(true) }
|
15
|
+
assert_raises(ArgumentError) { Workbook::Column.new(nil, {:limit=>20,:default=>"asdf", :column_type=>:bodfolean}) }
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_table
|
19
19
|
c = Workbook::Column.new
|
20
20
|
c.table = Workbook::Table.new
|
21
21
|
assert_equal(Workbook::Table.new, c.table)
|
22
|
-
|
22
|
+
assert_raises(ArgumentError) { c.table = false }
|
23
23
|
end
|
24
24
|
end
|
data/test/test_format.rb
CHANGED
data/test/test_functional.rb
CHANGED
data/test/test_modules_cache.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
3
3
|
module Modules
|
4
|
-
class TestTableDiffSort < Test
|
4
|
+
class TestTableDiffSort < Minitest::Test
|
5
5
|
def test_sort
|
6
6
|
time = Time.now
|
7
7
|
b = Workbook::Book.new [[1,2,3],[2,2,3],[true,false,true],["asdf","sdf","as"],[time,2,3],[2,2,2],[22,2,3],[1,2,233]]
|
@@ -20,7 +20,7 @@ module Modules
|
|
20
20
|
|
21
21
|
ba = Workbook::Book.new [['a','b','c','d'],[1,2,3,4],[4,2,3,4],[3,2,3,4]]
|
22
22
|
sba = ba.sheet.table.sort
|
23
|
-
|
23
|
+
refute_equal(Workbook::Table.new([['a','b','c','d'],[1,2,3,4],[4,2,3,4],[3,2,3,4]]),sba)
|
24
24
|
assert_equal(Workbook::Table.new([['a','b','c','d'],[1,2,3,4],[3,2,3,4],[4,2,3,4]]),sba)
|
25
25
|
|
26
26
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
3
3
|
module Modules
|
4
|
-
class TestTypeParser < Test
|
4
|
+
class TestTypeParser < Minitest::Test
|
5
5
|
def examples
|
6
6
|
{"2312"=>2312,
|
7
7
|
"12-12-2012"=>Date.new(2012,12,12),
|
@@ -35,7 +35,7 @@ module Modules
|
|
35
35
|
examples.each do |k,v|
|
36
36
|
c = Workbook::Cell.new(k)
|
37
37
|
c.string_parsers = customparsers
|
38
|
-
|
38
|
+
refute_equal(v,c.parse)
|
39
39
|
end
|
40
40
|
c = Workbook::Cell.new("233")
|
41
41
|
c.string_parsers = customparsers
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
3
3
|
module Readers
|
4
|
-
class TestCsvWriter < Test
|
4
|
+
class TestCsvWriter < Minitest::Test
|
5
5
|
def test_open
|
6
6
|
w = Workbook::Book.new
|
7
7
|
w.open File.join(File.dirname(__FILE__), 'artifacts/simple_csv.csv')
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
3
3
|
module Readers
|
4
|
-
class TestTxtReader < Test
|
4
|
+
class TestTxtReader < Minitest::Test
|
5
5
|
# Should one day throw an error..
|
6
6
|
# def test_failure_excel_as_txt_open
|
7
7
|
# w = Workbook::Book.new
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
3
3
|
module Readers
|
4
|
-
class TestXlsWriter < Test
|
4
|
+
class TestXlsWriter < Minitest::Test
|
5
5
|
def test_xls_open
|
6
6
|
w = Workbook::Book.new
|
7
7
|
w.open File.join(File.dirname(__FILE__), 'artifacts/book_with_tabs_and_colours.xls')
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
3
3
|
module Readers
|
4
|
-
class TestXlsxWriter < Test
|
4
|
+
class TestXlsxWriter < Minitest::Test
|
5
5
|
def test_xlsx_open
|
6
6
|
w = Workbook::Book.new
|
7
7
|
w.open File.join(File.dirname(__FILE__), 'artifacts/book_with_tabs_and_colours.xlsx')
|
data/test/test_row.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
3
3
|
|
4
|
-
class TestRow < Test
|
4
|
+
class TestRow < Minitest::Test
|
5
5
|
|
6
6
|
|
7
7
|
def test_init
|
@@ -25,7 +25,7 @@ class TestRow < Test::Unit::TestCase
|
|
25
25
|
|
26
26
|
def test_table=
|
27
27
|
r = Workbook::Row.new
|
28
|
-
|
28
|
+
assert_raises(ArgumentError, 'table should be a Workbook::Table (you passed a String)') { r.table = "asdf" }
|
29
29
|
r.table = nil
|
30
30
|
assert_equal(r.table, nil)
|
31
31
|
r = Workbook::Row.new
|
@@ -89,7 +89,7 @@ class TestRow < Test::Unit::TestCase
|
|
89
89
|
|
90
90
|
def test_to_hash
|
91
91
|
r1 = Workbook::Row.new ["test", "asdf-asd", "asdf - asdf", "asdf2"]
|
92
|
-
|
92
|
+
assert_raises(NoMethodError, 'undefined method `header\' for nil:NilClass') { r1.to_hash }
|
93
93
|
|
94
94
|
t = Workbook::Table.new
|
95
95
|
r1 = Workbook::Row.new ["test", "asdf-asd"]
|
data/test/test_sheet.rb
CHANGED
data/test/test_table.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
3
3
|
|
4
|
-
class TestTable< Test
|
4
|
+
class TestTable< Minitest::Test
|
5
5
|
def test_initialize
|
6
6
|
t = Workbook::Table.new
|
7
7
|
assert_equal(t,[])
|
@@ -184,7 +184,7 @@ class TestTable< Test::Unit::TestCase
|
|
184
184
|
first_few_lines = table[12][0].value - table[2][0].value
|
185
185
|
last_few_lines = table[last_line][0].value - table[last_line-10][0].value
|
186
186
|
# puts [first_few_lines,last_few_lines].join(" vs ")
|
187
|
-
assert_equal(true, first_few_lines*1.
|
187
|
+
assert_equal(true, first_few_lines*1.20 > last_few_lines) # 10% slower is acceptable
|
188
188
|
end
|
189
189
|
|
190
190
|
|
data/test/test_template.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
3
3
|
|
4
4
|
module Writers
|
5
|
-
class TestHtmlWriter < Test
|
5
|
+
class TestHtmlWriter < Minitest::Test
|
6
6
|
def test_to_html
|
7
7
|
#jruby and ruby's output differ a bit... both produce valid results though
|
8
8
|
# match = Workbook::Book.new.to_html.match(/<table \/>/) ? true : false #jruby
|
@@ -2,7 +2,7 @@
|
|
2
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
3
3
|
|
4
4
|
module Writers
|
5
|
-
class TestJsonWriter < Test
|
5
|
+
class TestJsonWriter < Minitest::Test
|
6
6
|
def test_to_array_of_hashes_with_values
|
7
7
|
assert_equal([],Workbook::Table.new.to_array_of_hashes_with_values)
|
8
8
|
assert_equal([],Workbook::Table.new([["a","b"]]).to_array_of_hashes_with_values)
|
@@ -2,7 +2,7 @@
|
|
2
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
3
3
|
|
4
4
|
module Writers
|
5
|
-
class TestXlsWriter < Test
|
5
|
+
class TestXlsWriter < Minitest::Test
|
6
6
|
def test_to_xls
|
7
7
|
b = Workbook::Book.new [['a','b','c'],[1,2,3],[3,2,3]]
|
8
8
|
raw = Spreadsheet.open File.join(File.dirname(__FILE__), 'artifacts/simple_sheet.xls')
|
@@ -2,7 +2,7 @@
|
|
2
2
|
require File.join(File.dirname(__FILE__), 'helper')
|
3
3
|
|
4
4
|
module Writers
|
5
|
-
class TestXlsxWriter < Test
|
5
|
+
class TestXlsxWriter < Minitest::Test
|
6
6
|
def test_empty_to_xlsx
|
7
7
|
b = Workbook::Book.new [['a','b','c'],[1,2,3],[3,2,3]]
|
8
8
|
b.to_xlsx.is_a? RubyXL::Workbook
|
data/workbook.gemspec
CHANGED
@@ -16,12 +16,13 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.add_development_dependency 'ruby-prof', '~> 0.14'
|
17
17
|
s.add_dependency('rubyzip', '~>1')
|
18
18
|
s.add_dependency('spreadsheet', '~> 1.0')
|
19
|
+
s.add_development_dependency('minitest', '~> 5.4')
|
19
20
|
s.add_dependency('fastercsv') if RUBY_VERSION < "1.9"
|
20
21
|
s.add_dependency("rchardet", "~> 1.3")
|
21
22
|
s.add_dependency("rake", '~> 10.0')
|
22
23
|
s.add_dependency("json", '~> 1.8')
|
23
24
|
s.add_dependency("zip-zip", '~> 0.2') #actually a hack...
|
24
|
-
s.add_dependency('rubyXL', '~>
|
25
|
+
s.add_dependency('rubyXL', '~> 3.3')
|
25
26
|
if RUBY_VERSION < "1.9"
|
26
27
|
s.add_dependency('nokogiri', "~> 1.5.10")
|
27
28
|
else
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: workbook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maarten Brouwers
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.4'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rchardet
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +128,14 @@ dependencies:
|
|
114
128
|
requirements:
|
115
129
|
- - "~>"
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
131
|
+
version: '3.3'
|
118
132
|
type: :runtime
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
136
|
- - "~>"
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
138
|
+
version: '3.3'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: nokogiri
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|