workbook 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c0a6519a54a39e28ff553a4c91ed323bc1ea26cb
4
+ data.tar.gz: 2fc5bc899ed4347d5010b98224f9eb28d6895df8
5
+ SHA512:
6
+ metadata.gz: c62b71197742c0b0e4d99890e7e695daaa4b22b3a91dc575c085fe4ab4309d731d3e03539e0995bc15201ebf90c75c925a3cd84f60cb0ff8e48fc67bb6c4d88a
7
+ data.tar.gz: 11b95b6db274135ea696380bca9d0b35e939cca6182fcf368b1b10b56d91886d5fc30a3b5ab06c03c60676fff348d9a66b2fe3a04cde0603ad6a22a661b2965b
data/lib/workbook/book.rb CHANGED
@@ -22,9 +22,6 @@ module Workbook
22
22
  include Workbook::Readers::CsvReader
23
23
  include Workbook::Readers::TxtReader
24
24
 
25
- attr_accessor :title
26
- attr_accessor :template
27
-
28
25
  # @param [Workbook::Sheet, Array] sheet create a new workbook based on an existing sheet, or initialize a sheet based on the array
29
26
  # @return [Workbook::Book]
30
27
  def initialize sheet=Workbook::Sheet.new([], self, options={})
@@ -53,6 +50,10 @@ module Workbook
53
50
  @title ? @title : "untitled document"
54
51
  end
55
52
 
53
+ def title= t
54
+ @title = t
55
+ end
56
+
56
57
  # Push (like in array) a sheet to the workbook (parameter is optional, default is a new sheet)
57
58
  #
58
59
  # @param [Workbook::Sheet] sheet
@@ -112,6 +113,15 @@ module Workbook
112
113
  send("load_#{extension}".to_sym,t)
113
114
  end
114
115
 
116
+ # Writes the book to a file. Filetype is based on the extension, but can be overridden
117
+ #
118
+ # @param [String] filename a string with a reference to the file to be written to
119
+ # @param [Hash] options depends on the writer chosen by the file's filetype
120
+ def write filename, options
121
+ extension = file_extension(filename)
122
+ send("write_to_#{extension}".to_sym, filename, options)
123
+ end
124
+
115
125
 
116
126
  # Helper method to convert text in a file to UTF-8
117
127
  #
data/lib/workbook/cell.rb CHANGED
@@ -6,11 +6,7 @@ module Workbook
6
6
  class Cell
7
7
  include Workbook::Modules::TypeParser
8
8
 
9
- attr_accessor :value
10
- attr_accessor :format
11
9
  attr_accessor :formula
12
- attr_accessor :colspan
13
- attr_accessor :rowspan
14
10
 
15
11
  # Note that these types are sorted by 'importance'
16
12
  VALID_TYPES = [Numeric,String,Time,Date,TrueClass,FalseClass,NilClass,Workbook::NilValue]
@@ -29,7 +25,7 @@ module Workbook
29
25
  # @param [Hash] options a reference to :format (Workbook::Format) can be specified
30
26
  def initialize value=nil, options={}
31
27
  if valid_value? value
32
- format = options[:format]
28
+ self.format = options[:format]
33
29
  @value = value
34
30
  else
35
31
  raise ArgumentError, "value should be of a primitive type, e.g. a string, or an integer, not a #{value.class} (is_a? [TrueClass,FalseClass,Date,Time,Numeric,String, NilClass])"
@@ -47,6 +43,13 @@ module Workbook
47
43
  end
48
44
  end
49
45
 
46
+ # Returns the current value
47
+ #
48
+ # @return [Numeric,String,Time,Date,TrueClass,FalseClass,NilClass] a valid value
49
+ def value
50
+ @value
51
+ end
52
+
50
53
  # Change the current format
51
54
  #
52
55
  # @param [Workbook::Format, Hash] f set the formatting properties of this Cell
@@ -95,7 +98,7 @@ module Workbook
95
98
  v = nil
96
99
  if value
97
100
  v = value.to_s.downcase
98
- v = v.gsub(' (j/?/leeg)','').gsub(/dd-mm-(.*)/,'').gsub(/\ja\/nee/,'').gsub(/\(\)/,'').gsub(/[\(\)]+/, '')
101
+ v = v.gsub(' (j/?/leeg)','').gsub(/dd-mm-(.*)/,'').gsub(/ja\/nee/,'').gsub(/\(\)/,'').gsub(/[\(\)]+/, '')
99
102
  v = v.strip.gsub(/(\.|\?|,|\=)/,'').
100
103
  gsub('$','').
101
104
  gsub(/\&/,'en').
@@ -147,7 +150,7 @@ module Workbook
147
150
  rv = nil
148
151
  begin
149
152
  rv = self.value <=> other.value
150
- rescue NoMethodError => e
153
+ rescue NoMethodError
151
154
  rv = compare_on_class other
152
155
  end
153
156
  if rv == nil
@@ -192,11 +195,18 @@ module Workbook
192
195
  end
193
196
  end
194
197
 
198
+ def colspan= c
199
+ @colspan = c
200
+ end
201
+ def rowspan= r
202
+ @rowspan = r
203
+ end
204
+
195
205
  def colspan
196
- @colspan.to_i if @colspan.to_i > 1
206
+ @colspan.to_i if defined?(@colspan) and @colspan.to_i > 1
197
207
  end
198
208
  def rowspan
199
- @rowspan.to_i if @rowspan.to_i > 1
209
+ @rowspan.to_i if defined?(@rowspan) and @rowspan.to_i > 1
200
210
  end
201
211
  end
202
212
  end
@@ -3,14 +3,17 @@ module Workbook
3
3
 
4
4
  # Column helps us to store general properties of a column, and lets us easily perform operations on values within a column
5
5
  class Column
6
- attr_accessor :column_type # :primary_key, :string, :text, :integer, :float, :decimal, :datetime, :date, :binary, :boolean.
7
6
  attr_accessor :limit #character limit
8
- attr_accessor :default #default cell
9
7
 
10
8
  def initialize(options={})
11
9
  options.each{ |k,v| self.public_send("#{k}=",v) }
12
10
  end
13
11
 
12
+ # Returns column type, either :primary_key, :string, :text, :integer, :float, :decimal, :datetime, :date, :binary, :boolean
13
+ def column_type
14
+ @column_type
15
+ end
16
+
14
17
  def column_type= column_type
15
18
  if [:primary_key, :string, :text, :integer, :float, :decimal, :datetime, :date, :binary, :boolean].include? column_type
16
19
  @column_type = column_type
@@ -20,6 +23,11 @@ module Workbook
20
23
  end
21
24
  end
22
25
 
26
+ #default cell
27
+ def default
28
+ return @default
29
+ end
30
+
23
31
  def default= value
24
32
  @default = value if value.class == Cell
25
33
  @default = Cell.new(value)
@@ -80,7 +80,6 @@ module Workbook
80
80
 
81
81
  options = {:sort=>true,:ignore_headers=>false}.merge(options)
82
82
 
83
- iteration_cols = nil
84
83
  sother = other.clone.remove_empty_lines!
85
84
  sself = self.clone.remove_empty_lines!
86
85
 
@@ -92,8 +91,6 @@ module Workbook
92
91
  sother = options[:sort] ? Workbook::Table.new(sother.sort) : sother
93
92
  sself = options[:sort] ? Workbook::Table.new(sself.sort) : sself
94
93
 
95
- iteration_rows = [sother.count,sself.count].max.times.collect
96
-
97
94
  row_index = 0
98
95
  while row_index < [sother.count,sself.count].max and row_index < other.count+self.count do
99
96
  row_index = align_row(sself, sother, row_index)
@@ -2,7 +2,6 @@ module Workbook
2
2
 
3
3
  # Used in cases col or rowspans are used
4
4
  class NilValue
5
- attr_accessor :reason #:covered
6
5
 
7
6
  # initialize this special nilvalue with a reason
8
7
  # @params [String] reason (currently only :covered, in case this cell is coverd because an adjecant cell spans over it)
@@ -20,6 +19,10 @@ module Workbook
20
19
  value <=> v
21
20
  end
22
21
 
22
+ def reason
23
+ @reason
24
+ end
25
+
23
26
  # set the reason why this value is nil
24
27
  def reason= reason
25
28
  if reason == :covered
@@ -81,7 +81,6 @@ module Workbook
81
81
 
82
82
  #set column count
83
83
  def get_column_count(table)
84
- init_column_count = table.xpath("table:table-column").count
85
84
  first_row = table.xpath("table:table-row").first
86
85
  cells = first_row.xpath("table:table-cell|table:covered-table-cell")
87
86
  column_count = 0
@@ -7,7 +7,7 @@ module Workbook
7
7
 
8
8
  def load_xls file_obj
9
9
  begin
10
- sp = Spreadsheet.open(file_obj, mode='rb')
10
+ sp = Spreadsheet.open(file_obj, 'rb')
11
11
  template.add_raw sp
12
12
  parse_xls sp
13
13
  rescue Ole::Storage::FormatError => e
@@ -2,7 +2,6 @@
2
2
  module Workbook
3
3
  class Sheet < Array
4
4
  # A Sheet is a container of tables
5
- attr_accessor :book
6
5
  attr_accessor :name
7
6
 
8
7
  # Initialize a new sheet
@@ -61,6 +60,10 @@ module Workbook
61
60
  end
62
61
  end
63
62
 
63
+ def book= b
64
+ @book = b
65
+ end
66
+
64
67
  # Removes all lines from this table
65
68
  #
66
69
  # @return [Workbook::Table] (self)
@@ -12,7 +12,6 @@ module Workbook
12
12
  include Workbook::Writers::JsonTableWriter
13
13
  attr_accessor :sheet
14
14
  attr_accessor :name
15
- attr_accessor :header
16
15
 
17
16
  def initialize row_cel_values=[], sheet=nil, options={}
18
17
  row_cel_values = [] if row_cel_values == nil
@@ -32,15 +31,19 @@ module Workbook
32
31
  #
33
32
  # @return [Workbook::Row] The header
34
33
  def header
35
- if @header == false
34
+ if defined?(@header) and @header == false
36
35
  false
37
- elsif @header
36
+ elsif defined?(@header) and @header
38
37
  @header
39
38
  else
40
39
  first
41
40
  end
42
41
  end
43
42
 
43
+ def header= h
44
+ @header = h
45
+ end
46
+
44
47
  # Generates a new row, with optionally predefined cell-values, that is already connected to this table.
45
48
  def new_row cell_values=[]
46
49
  r = Workbook::Row.new(cell_values,self)
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Workbook
3
- VERSION = '0.4.4'
3
+ VERSION = '0.4.5'
4
4
  end
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 TestRow < Test::Unit::TestCase
4
+ class TestColumn < Test::Unit::TestCase
5
5
 
6
6
  def test_init
7
7
  c = Workbook::Column.new
@@ -1,8 +1,8 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  require File.join(File.dirname(__FILE__), 'helper')
3
3
  module Readers
4
- class TestXlsWriter < Test::Unit::TestCase
5
- def test_open
4
+ class TestOdsWriter < Test::Unit::TestCase
5
+ def test_ods_open
6
6
 
7
7
  w = Workbook::Book.new
8
8
  w.open File.join(File.dirname(__FILE__), 'artifacts/book_with_tabs_and_colours.ods')
@@ -2,7 +2,7 @@
2
2
  require File.join(File.dirname(__FILE__), 'helper')
3
3
  module Readers
4
4
  class TestXlsWriter < Test::Unit::TestCase
5
- def test_open
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')
8
8
  assert_equal([:a, :b, :c, :d, :e],w.sheet.table.header.to_symbols)
@@ -15,7 +15,7 @@ module Readers
15
15
 
16
16
  end
17
17
 
18
- def test_complex_types
18
+ def test_xls_complex_types
19
19
  w = Workbook::Book.new
20
20
  w.open File.join(File.dirname(__FILE__), 'artifacts/complex_types.xls')
21
21
  assert_equal(Date.new(2011,11,15), w.sheet.table[2][3].value)
@@ -24,7 +24,7 @@ module Readers
24
24
  assert_equal(1.2, w.sheet.table[3][1].value)
25
25
  end
26
26
 
27
- def test_excel_standardized_open
27
+ def test_xls_excel_standardized_open
28
28
  w = Workbook::Book.new
29
29
  w.open(File.join(File.dirname(__FILE__), "artifacts/excel_different_types.xls"))
30
30
  # reads
@@ -2,7 +2,7 @@
2
2
  require File.join(File.dirname(__FILE__), 'helper')
3
3
  module Readers
4
4
  class TestXlsxWriter < Test::Unit::TestCase
5
- def test_open
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')
8
8
  assert_equal([:a, :b, :c, :d, :e],w.sheet.table.header.to_symbols)
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
5
- prerelease:
4
+ version: 0.4.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Maarten Brouwers
@@ -14,7 +13,6 @@ dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rubyzip
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - '='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - '='
28
25
  - !ruby/object:Gem::Version
@@ -30,97 +27,85 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: spreadsheet
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: 0.7.5
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: 0.7.5
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rchardet
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '1.3'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: '1.3'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: json
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :runtime
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rubyXL
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :runtime
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - ">="
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: nokogiri
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - ">="
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :runtime
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - ">="
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  description: Workbook contains workbooks, as in a table, contains rows, contains cells,
@@ -128,20 +113,22 @@ description: Workbook contains workbooks, as in a table, contains rows, contains
128
113
  and sorting capabilities.
129
114
  email:
130
115
  - gem@murb.nl
131
- executables: []
116
+ executables:
117
+ - axldiff
132
118
  extensions: []
133
119
  extra_rdoc_files: []
134
120
  files:
135
- - .gitignore
136
- - .travis.yml
137
- - .yardoc/checksums
138
- - .yardoc/object_types
139
- - .yardoc/objects/root.dat
140
- - .yardoc/proxy_types
121
+ - ".gitignore"
122
+ - ".travis.yml"
123
+ - ".yardoc/checksums"
124
+ - ".yardoc/object_types"
125
+ - ".yardoc/objects/root.dat"
126
+ - ".yardoc/proxy_types"
141
127
  - Gemfile
142
128
  - LICENSE.txt
143
129
  - README.md
144
130
  - Rakefile
131
+ - bin/axldiff
145
132
  - doc/RubyXL.html
146
133
  - doc/RubyXL/Cell.html
147
134
  - doc/RubyXL/Workbook.html
@@ -253,27 +240,26 @@ files:
253
240
  - workbook.gemspec
254
241
  homepage: http://murb.nl/blog?tags=workbook
255
242
  licenses: []
243
+ metadata: {}
256
244
  post_install_message:
257
245
  rdoc_options: []
258
246
  require_paths:
259
247
  - lib
260
248
  required_ruby_version: !ruby/object:Gem::Requirement
261
- none: false
262
249
  requirements:
263
- - - ! '>='
250
+ - - ">="
264
251
  - !ruby/object:Gem::Version
265
252
  version: '0'
266
253
  required_rubygems_version: !ruby/object:Gem::Requirement
267
- none: false
268
254
  requirements:
269
- - - ! '>='
255
+ - - ">="
270
256
  - !ruby/object:Gem::Version
271
257
  version: '0'
272
258
  requirements: []
273
259
  rubyforge_project: workbook
274
- rubygems_version: 1.8.23
260
+ rubygems_version: 2.2.0
275
261
  signing_key:
276
- specification_version: 3
262
+ specification_version: 4
277
263
  summary: Workbook is a datastructure to contain books of tables (an anlogy used in
278
264
  e.g. Excel)
279
265
  test_files: