workbook 0.7.6 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 56d83b87195be3cc4e75e0dc506b83ea006340f0
4
- data.tar.gz: 2f2611f84ff878b209b224d7976b3a753930f8e6
2
+ SHA256:
3
+ metadata.gz: 2d11f35120106855bbb5905a7f2611b138293157e135f86b0d8f5248c90f5f83
4
+ data.tar.gz: ced9b91f1f1f69bbe90151ef78f61885a1ced541c5d3392e46dcb4e7770b58da
5
5
  SHA512:
6
- metadata.gz: 612e20add890b9acc8d709816de0a50e43ef0ff7801091c9210f70ced0ef2effca9313a506a3beb003855b23f68bbc4d71cd0a342b71e15b028fc53c13a5e4e8
7
- data.tar.gz: 922031e7a87f9bfd919b4ef549f9a076de4f58747657ce8cd02bbbe771c06471be71edbd1b1c8be4cfdffbcd01b5c17a5089384df2d163f7dd63edf804f74133
6
+ metadata.gz: 1abccd53682ea4a4718153f0409e43925108740004dfbbba78419d4f80dd7a23add4677c7430812253a6e5559322b1919fb0f2c8f4450575804c8aae68056db6
7
+ data.tar.gz: 6eb31d092e13c909e6d96d78a594bd3c1e9abd01d88a8cb76fc133c128035786d7f06651123e4c2f0798fa7d8b275f6914ed21152a0eab94efbb80e03083cb95
@@ -0,0 +1 @@
1
+ 2.6.0
@@ -4,11 +4,10 @@ env:
4
4
  sudo: false
5
5
  language: ruby
6
6
  rvm:
7
- - 2.1.0
8
- - 2.2.0
9
7
  - 2.3.0
10
8
  - 2.4.0
11
9
  - 2.5.0
10
+ - 2.6.0
12
11
  before_install:
13
12
  - gem install bundler
14
13
  before_script:
@@ -5,5 +5,14 @@ require 'workbook/modules/cell'
5
5
  module Workbook
6
6
  class Cell
7
7
  include Workbook::Modules::Cell
8
+
9
+ # @param [Numeric,String,Time,Date,TrueClass,FalseClass,NilClass] value a valid value
10
+ # @param [Hash] options a reference to :format (Workbook::Format) can be specified
11
+ def initialize value=nil, options={}
12
+ self.format = options[:format] if options[:format]
13
+ self.row = options[:row]
14
+ self.value = value
15
+ @to_sym = nil
16
+ end
8
17
  end
9
18
  end
@@ -81,15 +81,6 @@ module Workbook
81
81
  @row= r
82
82
  end
83
83
 
84
- # @param [Numeric,String,Time,Date,TrueClass,FalseClass,NilClass] value a valid value
85
- # @param [Hash] options a reference to :format (Workbook::Format) can be specified
86
- def initialize value=nil, options={}
87
- self.format = options[:format] if options[:format]
88
- self.row = options[:row]
89
- self.value = value
90
- @to_sym = nil
91
- end
92
-
93
84
  # Change the current value
94
85
  #
95
86
  # @param [Numeric,String,Time,Date,TrueClass,FalseClass,NilClass,Symbol] value a valid value
@@ -196,8 +187,7 @@ module Workbook
196
187
  elsif cell_type == :float
197
188
  v = "num#{value}".sub(".","_").to_sym
198
189
  else
199
- v = value_to_s
200
-
190
+ v = value_to_s.strip
201
191
  ends_with_exclamationmark = (v[-1] == '!')
202
192
  ends_with_questionmark = (v[-1] == '?')
203
193
 
@@ -78,30 +78,55 @@ module Workbook
78
78
 
79
79
  def string_optimistic_date_converter
80
80
  proc do |v|
81
- rv = v
82
- starts_with_nr = v.chars.first.to_i.to_s == v.chars.first #it should at least start with a number...
83
- no_spaced_dash = v.to_s.match(" - ") ? false : true
84
- min_two_dashes = v.to_s.scan("-").count > 1 ? true : false
85
- min_two_dashes = v.to_s.scan("/").count > 1 ? true : false if min_two_dashes == false
81
+ if v
82
+ rv = v
83
+ starts_with_nr = v.chars.first.to_i.to_s == v.chars.first #it should at least start with a number...
84
+ no_spaced_dash = v.to_s.match(" - ") ? false : true
85
+ min_two_dashes = v.to_s.scan("-").count > 1 ? true : false
86
+ min_two_dashes = v.to_s.scan("/").count > 1 ? true : false if min_two_dashes == false
86
87
 
87
- normal_date_length = v.to_s.length <= 25
88
- if no_spaced_dash and starts_with_nr and normal_date_length and min_two_dashes
89
- begin
90
- rv = (v.length > 10) ? DateTime.parse(v) : Date.parse(v)
91
- rescue ArgumentError
92
- rv = v
93
- end
94
- begin
95
- rv = Date.parse(v.to_i.to_s) == rv ? v : rv # disqualify if it is only based on the first number
96
- rescue ArgumentError
88
+ normal_date_length = v.to_s.length <= 25
89
+ if no_spaced_dash and starts_with_nr and normal_date_length and min_two_dashes
90
+ begin
91
+ rv = (v.length > 10) ? DateTime.parse(v) : Date.parse(v)
92
+ rescue ArgumentError
93
+ rv = v
94
+ end
95
+ begin
96
+ rv = Date.parse(v.to_i.to_s) == rv ? v : rv # disqualify if it is only based on the first number
97
+ rescue ArgumentError
98
+ end
97
99
  end
100
+ rv
101
+ end
102
+ end
103
+ end
104
+
105
+ def string_american_date_converter
106
+ proc do |v|
107
+ if v
108
+ rv = v
98
109
  # try strptime with format 'mm/dd/yyyy'
99
- if rv == v && /^\d{1,2}[\/-]\d{1,2}[\/-]\d{4}/ =~ v
110
+ if rv.is_a?(String) && /^\d{1,2}[\/-]\d{1,2}[\/-]\d{4}/ =~ v
100
111
  begin
101
112
  rv = Date.strptime(v, "%m/%d/%Y")
102
113
  rescue ArgumentError
103
114
  end
104
115
  end
116
+ rv
117
+ end
118
+ end
119
+ end
120
+
121
+ def string_non_american_date_converter
122
+ proc do |v|
123
+ rv = v
124
+ # try strptime with format 'mm/dd/yyyy'
125
+ if rv.is_a?(String) && /^\d{1,2}[\/\-\.]\d{1,2}[\/\-\.]\d{4}/ =~ v
126
+ begin
127
+ rv = Date.strptime(v, "%m/%d/%Y")
128
+ rescue ArgumentError
129
+ end
105
130
  end
106
131
  rv
107
132
  end
@@ -14,19 +14,18 @@ module Workbook
14
14
  end
15
15
 
16
16
  def parse_csv csv_raw, options={}
17
- custom_date_converter = Workbook::Cell.new.string_optimistic_date_converter
17
+ optimistic_date_converter = Workbook::Cell.new.string_optimistic_date_converter
18
18
  options = {
19
- converters: [:all,custom_date_converter]
19
+ converters: [optimistic_date_converter, :all]
20
20
  }.merge(options)
21
21
 
22
- csv=nil
23
- begin
24
- csv = CSV.parse(csv_raw,options)
22
+ csv = nil
25
23
 
24
+ begin
25
+ csv = CSV.parse(csv_raw, options)
26
26
  rescue CSV::MalformedCSVError
27
27
  csv_excel = CSV.parse(csv_raw,options.merge({:col_sep=>';'}))
28
28
  csv = csv_excel if csv_excel[0].count > 1
29
-
30
29
  end
31
30
 
32
31
  if csv==nil or csv[0].count == 1
@@ -34,7 +33,7 @@ module Workbook
34
33
  csv = csv_excel if csv_excel[0].count > 1
35
34
  end
36
35
 
37
- self[0]=Workbook::Sheet.new(csv,self) unless sheet.has_contents?
36
+ self[0] = Workbook::Sheet.new(csv, self) unless sheet.has_contents?
38
37
  end
39
38
 
40
39
  end
@@ -188,6 +188,12 @@ module Workbook
188
188
  elsif type == "n"
189
189
  value = value.match(/\./) ? value.to_f : value.to_i
190
190
  end
191
+ elsif type == "b"
192
+ if value.to_s == "0"
193
+ value = false
194
+ elsif value.to_s == "1"
195
+ value = true
196
+ end
191
197
  elsif type == "s"
192
198
  value = @shared_strings[value.to_i]
193
199
  end
@@ -1,5 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  # frozen_string_literal: true
3
3
  module Workbook
4
- VERSION = '0.7.6'
4
+ VERSION = '0.8.0'
5
5
  end
@@ -88,7 +88,10 @@ class TestModulesCell < Minitest::Test
88
88
  "A-B!" => :ab!,
89
89
  "éåšžÌ?" => :easzi?,
90
90
  1 => :num1,
91
- 1.0 => :num1_0
91
+ 1.0 => :num1_0,
92
+ 'test ' => :test,
93
+ 'test ' => :test
94
+
92
95
  }
93
96
  examples.each do |k,v|
94
97
  assert_equal(v, Workbook::Cell.new(k).to_sym)
@@ -12,7 +12,7 @@ module Modules
12
12
  "20-2-2012 20:52"=>DateTime.new(2012,2,20,20,52),
13
13
  "1-11-2011"=>Date.new(2011,11,1),
14
14
  "12/12/2012"=>Date.new(2012,12,12),
15
- "12/23/1980"=>Date.new(1980,12,23), #TODO: should probably depend on locale, see: http://bugs.ruby-lang.org/issues/634#note-10
15
+ # "12/23/1980"=>Date.new(1980,12,23), #TODO: should probably depend on locale, see: http://bugs.ruby-lang.org/issues/634#note-10
16
16
  "jA"=>"jA",
17
17
  "n"=>"n",
18
18
  ""=>nil,
@@ -27,7 +27,11 @@ module Modules
27
27
 
28
28
  def test_parse
29
29
  examples.each do |k,v|
30
- assert(v == Workbook::Cell.new(k).parse({:detect_date => true}))
30
+ if v == nil
31
+ assert_nil(Workbook::Cell.new(k).parse({:detect_date => true}))
32
+ else
33
+ assert_equal(v, Workbook::Cell.new(k).parse({:detect_date => true}))
34
+ end
31
35
  end
32
36
  end
33
37
 
@@ -48,6 +48,14 @@ module Readers
48
48
  assert(t["A2"].value.is_a?(Date))
49
49
  assert((Date.new(2012,2,22)-t["A2"].value) < 0.00001)
50
50
  assert((Date.new(2014,12,27)-t["B2"].value) < 0.00001)
51
+ assert_equal(false,t["E2"].value)
52
+ assert_equal(true,t["E3"].value)
53
+ assert_equal(true,t["E4"].value)
54
+ end
55
+ def test_skipping_cells
56
+ w = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/skippingcells.xlsx')
57
+ t = w.sheet.table
58
+ assert_equal("a,b,c,d,e,f,g,h,i,j,k,l,m,n\n1,,,,,,,,,,,,,\n,2,,,,,,,,,,,,\n,,3,,,,,,,,,,,\n,,,4,,,,,,,,,,\n,,,,5,,,,,,,,,\n,,,,,6,,,,,,,,\n,,,,,,7,,,,,,,\n,,,,,,,8,,,,,,\n,,,,,,,,9,,,,,\n,,,,,,,,,10,,,,\n,,,,,,,,,,11,,,\n,,,,,,,,,,,12,,\n,,,,,,,,,,,,13,\n,,,,,,,,,,,,,14\na,,,,,,,,,,,,,\n,b,,,,,,,,,,,,\n,,c,,,,,,,,,,,\n,,,d,,,,,,,,,,\n,,,,e,,,,,,,,,\n,,,,,f,,,,,,,,\n,,,,,,g,,,,,,,\n,,,,,,,h,,,,,,\n,,,,,,,,i,,,,,\n,,,,,,,,,j,,,,\n,,,,,,,,,,k,,,\n,,,,,,,,,,,l,,\n,,,,,,,,,,,,m,\n,,,,,,,,,,,,,n\n", t.to_csv)
51
59
  end
52
60
  def test_bit_table_xlsx
53
61
  b = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/bigtable.xlsx')
@@ -125,6 +125,7 @@ class TestTable< Minitest::Test
125
125
  w2.sheet.table = t[2..3]
126
126
  assert_equal("1,2\n3,4\n", w2.sheet.table.to_csv)
127
127
  end
128
+
128
129
  def test_array_style_assignment
129
130
  w = Workbook::Book.new [["a","b"],[1,2],[3,4]]
130
131
  t = w.sheet.table
@@ -133,12 +134,14 @@ class TestTable< Minitest::Test
133
134
  t[2] = r
134
135
  assert_equal(t, r.table)
135
136
  end
137
+
136
138
  def test_delete_at
137
139
  w = Workbook::Book.new [["a","b"],[1,2],[3,4]]
138
140
  t = w.sheet.table
139
141
  t.delete_at 2
140
142
  assert_equal(1, t.last.first.value)
141
143
  end
144
+
142
145
  def test_trim!
143
146
  t = Workbook::Table.new
144
147
  t << [1,2,3]
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.description = "Workbook contains workbooks, as in a table, contains rows, contains cells, reads/writes excel, ods and csv and tab separated files, and offers basic diffing and sorting capabilities."
16
16
  s.authors = ["Maarten Brouwers"]
17
17
  s.add_development_dependency 'ruby-prof', '~> 0.14'
18
- s.add_development_dependency("rake", '~> 10.0')
18
+ s.add_development_dependency("rake", '~> 12.0')
19
19
  s.add_development_dependency('minitest', '~> 5.4')
20
20
  s.add_dependency('spreadsheet', '~> 1.1')
21
21
  s.add_dependency("rchardet", "~> 1.3")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maarten Brouwers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-03 00:00:00.000000000 Z
11
+ date: 2019-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-prof
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '12.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '12.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -133,6 +133,7 @@ extensions: []
133
133
  extra_rdoc_files: []
134
134
  files:
135
135
  - ".gitignore"
136
+ - ".ruby-version"
136
137
  - ".travis.yml"
137
138
  - ".yardoc/checksums"
138
139
  - ".yardoc/object_types"
@@ -208,6 +209,7 @@ files:
208
209
  - test/artifacts/simple_sheet.xls
209
210
  - test/artifacts/simple_sheet.xlsx
210
211
  - test/artifacts/simple_sheet_many_sheets.xls
212
+ - test/artifacts/skippingcells.xlsx
211
213
  - test/artifacts/txt_in_xls.xls
212
214
  - test/artifacts/xls_with_txt_extension.txt
213
215
  - test/artifacts/xlsx_with_empty_start.xlsx
@@ -256,8 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
256
258
  - !ruby/object:Gem::Version
257
259
  version: '0'
258
260
  requirements: []
259
- rubyforge_project: workbook
260
- rubygems_version: 2.6.11
261
+ rubygems_version: 3.0.1
261
262
  signing_key:
262
263
  specification_version: 4
263
264
  summary: Workbook is a datastructure to contain books of tables (an anlogy used in
@@ -289,6 +290,7 @@ test_files:
289
290
  - test/artifacts/simple_sheet.xls
290
291
  - test/artifacts/simple_sheet.xlsx
291
292
  - test/artifacts/simple_sheet_many_sheets.xls
293
+ - test/artifacts/skippingcells.xlsx
292
294
  - test/artifacts/txt_in_xls.xls
293
295
  - test/artifacts/xls_with_txt_extension.txt
294
296
  - test/artifacts/xlsx_with_empty_start.xlsx