creek 2.2 → 2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/creek.gemspec +1 -1
- data/lib/creek/styles/converter.rb +23 -14
- data/lib/creek/version.rb +1 -1
- data/spec/fixtures/sample_dates.xlsx +0 -0
- data/spec/fixtures/sheets/sample_dates.xlsx +0 -0
- data/spec/fixtures/sheets/single_data_programme.xlsx +0 -0
- data/spec/styles/converter_spec.rb +8 -1
- data/spec/test_spec.rb +31 -9
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb5f52bba0a71fddfc27213389475ad881b61e33
|
4
|
+
data.tar.gz: bad18bc3dadfb9412f354a2f527ede8cb16f8828
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: becc2db698fdc35b68279ec7df03c95c9b2d12920e2de4e34c83a724116174dfa81b4730152d5ef72b517b7cb26c4c3b5d6b89887a32f6e61bf62d2364344363
|
7
|
+
data.tar.gz: c3164d65efb54c5d14d31fcd91fc865db85ae1b032015076a7b80e3b329248148c62b8ec907c9098fef3f34c964bca8b650021b8bfad37062a0c58d7b8f3b4b7
|
data/creek.gemspec
CHANGED
@@ -60,8 +60,10 @@ module Creek
|
|
60
60
|
value.to_i
|
61
61
|
when :float, :percentage
|
62
62
|
value.to_f
|
63
|
-
when :date
|
63
|
+
when :date
|
64
64
|
convert_date(value, options)
|
65
|
+
when :time, :date_time
|
66
|
+
convert_datetime(value, options)
|
65
67
|
when :bignum
|
66
68
|
convert_bignum(value)
|
67
69
|
|
@@ -71,22 +73,17 @@ module Creek
|
|
71
73
|
end
|
72
74
|
end
|
73
75
|
|
74
|
-
# the trickiest. note that all these formats can vary on
|
75
|
-
# whether they actually contain a date, time, or datetime.
|
76
76
|
def self.convert_date(value, options)
|
77
|
-
|
78
|
-
|
79
|
-
fraction_of_24 = value - days_since_date_system_start
|
77
|
+
date = base_date(options) + value.to_i
|
78
|
+
yyyy, mm, dd = date.strftime('%Y-%m-%d').split('-')
|
80
79
|
|
81
|
-
|
82
|
-
|
80
|
+
::Date.new(yyyy.to_i, mm.to_i, dd.to_i)
|
81
|
+
end
|
83
82
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
return date
|
89
|
-
end
|
83
|
+
def self.convert_datetime(value, options)
|
84
|
+
date = base_date(options) + value.to_f.round(6)
|
85
|
+
|
86
|
+
round_datetime(date.strftime('%Y-%m-%d %H:%M:%S.%N'))
|
90
87
|
end
|
91
88
|
|
92
89
|
def self.convert_bignum(value)
|
@@ -96,6 +93,18 @@ module Creek
|
|
96
93
|
value.to_f
|
97
94
|
end
|
98
95
|
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def self.base_date(options)
|
100
|
+
options.fetch(:base_date, Date.new(1899, 12, 30))
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.round_datetime(datetime_string)
|
104
|
+
/(?<yyyy>\d+)-(?<mm>\d+)-(?<dd>\d+) (?<hh>\d+):(?<mi>\d+):(?<ss>\d+.\d+)/ =~ datetime_string
|
105
|
+
|
106
|
+
::Time.new(yyyy.to_i, mm.to_i, dd.to_i, hh.to_i, mi.to_i, ss.to_r).round(0)
|
107
|
+
end
|
99
108
|
end
|
100
109
|
end
|
101
110
|
end
|
data/lib/creek/version.rb
CHANGED
Binary file
|
Binary file
|
Binary file
|
@@ -3,13 +3,20 @@ require './spec/spec_helper'
|
|
3
3
|
describe Creek::Styles::Converter do
|
4
4
|
|
5
5
|
describe :call do
|
6
|
+
|
6
7
|
def convert(value, type, style)
|
7
8
|
Creek::Styles::Converter.call(value, type, style)
|
8
9
|
end
|
9
10
|
|
11
|
+
describe :date do
|
12
|
+
it "works" do
|
13
|
+
expect(convert('41275', 'n', :date)).to eq(Date.new(2013,01,01))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
10
17
|
describe :date_time do
|
11
18
|
it "works" do
|
12
|
-
expect(convert('41275', 'n', :date_time)).to eq(
|
19
|
+
expect(convert('41275', 'n', :date_time)).to eq(Time.new(2013,01,01))
|
13
20
|
end
|
14
21
|
end
|
15
22
|
end
|
data/spec/test_spec.rb
CHANGED
@@ -26,6 +26,34 @@ describe 'Creek trying to parsing an invalid file.' do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
describe 'Creek parsing dates on a sample XLSX file' do
|
30
|
+
before(:all) do
|
31
|
+
@creek = Creek::Book.new 'spec/fixtures/sample_dates.xlsx'
|
32
|
+
|
33
|
+
@expected_datetime_rows = [
|
34
|
+
{'A3' => 'Date', 'B3' => Date.parse('2018-01-01')},
|
35
|
+
{'A4' => 'Datetime 00:00:00', 'B4' => Time.parse('2018-01-01 00:00:00')},
|
36
|
+
{'A5' => 'Datetime', 'B5' => Time.parse('2018-01-01 23:59:59')}]
|
37
|
+
end
|
38
|
+
|
39
|
+
after(:all) do
|
40
|
+
@creek.close
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'parses dates successfully' do
|
44
|
+
rows = Array.new
|
45
|
+
row_count = 0
|
46
|
+
@creek.sheets[0].rows.each do |row|
|
47
|
+
rows << row
|
48
|
+
row_count += 1
|
49
|
+
end
|
50
|
+
|
51
|
+
(2..5).each do |number|
|
52
|
+
expect(rows[number]).to eq(@expected_datetime_rows[number-2])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
29
57
|
describe 'Creek parsing a sample XLSX file' do
|
30
58
|
before(:all) do
|
31
59
|
@creek = Creek::Book.new 'spec/fixtures/sample.xlsx'
|
@@ -63,15 +91,9 @@ describe 'Creek parsing a sample XLSX file' do
|
|
63
91
|
row_count += 1
|
64
92
|
end
|
65
93
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
expect(rows[3]).to eq(@expected_rows[3])
|
70
|
-
expect(rows[4]).to eq(@expected_rows[4])
|
71
|
-
expect(rows[5]).to eq(@expected_rows[5])
|
72
|
-
expect(rows[6]).to eq(@expected_rows[6])
|
73
|
-
expect(rows[7]).to eq(@expected_rows[7])
|
74
|
-
expect(rows[8]).to eq(@expected_rows[8])
|
94
|
+
(0..8).each do |number|
|
95
|
+
expect(rows[number]).to eq(@expected_rows[number])
|
96
|
+
end
|
75
97
|
expect(row_count).to eq(9)
|
76
98
|
end
|
77
99
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: creek
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '2.
|
4
|
+
version: '2.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pythonicrubyist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 3.0
|
103
|
+
version: '3.0'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 3.0
|
110
|
+
version: '3.0'
|
111
111
|
description: A Ruby gem that streams and parses large Excel(xlsx and xlsm) files fast
|
112
112
|
and efficiently.
|
113
113
|
email:
|
@@ -138,7 +138,10 @@ files:
|
|
138
138
|
- spec/fixtures/sample-as-zip.zip
|
139
139
|
- spec/fixtures/sample-with-images.xlsx
|
140
140
|
- spec/fixtures/sample.xlsx
|
141
|
+
- spec/fixtures/sample_dates.xlsx
|
142
|
+
- spec/fixtures/sheets/sample_dates.xlsx
|
141
143
|
- spec/fixtures/sheets/sheet1.xml
|
144
|
+
- spec/fixtures/sheets/single_data_programme.xlsx
|
142
145
|
- spec/fixtures/sst.xml
|
143
146
|
- spec/fixtures/styles/first.xml
|
144
147
|
- spec/fixtures/temp_string_io_file_path_with_no_extension
|
@@ -168,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
171
|
version: '0'
|
169
172
|
requirements: []
|
170
173
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.
|
174
|
+
rubygems_version: 2.6.14
|
172
175
|
signing_key:
|
173
176
|
specification_version: 4
|
174
177
|
summary: A Ruby gem for parsing large Excel(xlsx and xlsm) files.
|
@@ -178,7 +181,10 @@ test_files:
|
|
178
181
|
- spec/fixtures/sample-as-zip.zip
|
179
182
|
- spec/fixtures/sample-with-images.xlsx
|
180
183
|
- spec/fixtures/sample.xlsx
|
184
|
+
- spec/fixtures/sample_dates.xlsx
|
185
|
+
- spec/fixtures/sheets/sample_dates.xlsx
|
181
186
|
- spec/fixtures/sheets/sheet1.xml
|
187
|
+
- spec/fixtures/sheets/single_data_programme.xlsx
|
182
188
|
- spec/fixtures/sst.xml
|
183
189
|
- spec/fixtures/styles/first.xml
|
184
190
|
- spec/fixtures/temp_string_io_file_path_with_no_extension
|