xsv 1.0.1 → 1.0.2
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/xsv/helpers.rb +9 -27
- data/lib/xsv/shared_strings_parser.rb +9 -1
- data/lib/xsv/version.rb +1 -1
- data/lib/xsv/workbook.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6433d19ba65e00b98adecde398a3bfbfe9583ac811290d8f8ffa5ada16ea9b70
|
|
4
|
+
data.tar.gz: 903c61f9485f1380a064cc8ccfdfa378a46df1383259e6c82ca21501dcc485a5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e79c5866cd7dd20f0c36ea46a341234bcbc8cdbed40492c8bab31543fe96fcd4bd242a6c63368841e7ad481e4f72187eca5682effdb445388256e83969e1a969
|
|
7
|
+
data.tar.gz: 474da420765253453a3a1e9a25e8a2582052600bfdaee3e0f246db9d6b415a2a2ae46bd9c2edbb5364efb99708061125f189fd608cab5122bfc2090dd183004d
|
data/CHANGELOG.md
CHANGED
data/lib/xsv/helpers.rb
CHANGED
|
@@ -103,38 +103,20 @@ module Xsv
|
|
|
103
103
|
|
|
104
104
|
# Apply date or time number formats, if applicable
|
|
105
105
|
def parse_number_format(number, format)
|
|
106
|
-
number = parse_number(number)
|
|
106
|
+
number = parse_number(number) # number is always a string since it comes out of the Sax Parser
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
is_date_format = format.scan(/[dmy]+/).length > 1
|
|
109
|
+
is_time_format = format.scan(/[hms]+/).length > 1
|
|
110
|
+
|
|
111
|
+
if !is_date_format && !is_time_format
|
|
112
|
+
number
|
|
113
|
+
elsif is_date_format && is_time_format
|
|
109
114
|
parse_datetime(number)
|
|
110
|
-
elsif
|
|
115
|
+
elsif is_date_format
|
|
111
116
|
parse_date(number)
|
|
112
|
-
elsif
|
|
117
|
+
elsif is_time_format
|
|
113
118
|
parse_time(number)
|
|
114
|
-
else
|
|
115
|
-
number
|
|
116
119
|
end
|
|
117
120
|
end
|
|
118
|
-
|
|
119
|
-
# Tests if the given format string includes both date and time
|
|
120
|
-
def datetime_format?(format)
|
|
121
|
-
date_format?(format) && time_format?(format)
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
# Tests if the given format string is a date
|
|
125
|
-
def date_format?(format)
|
|
126
|
-
return false if format.nil?
|
|
127
|
-
|
|
128
|
-
# If it contains at least 2 sequences of d's, m's or y's it's a date!
|
|
129
|
-
format.scan(/[dmy]+/).length > 1
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
# Tests if the given format string is a time
|
|
133
|
-
def time_format?(format)
|
|
134
|
-
return false if format.nil?
|
|
135
|
-
|
|
136
|
-
# If it contains at least 2 sequences of h's, m's or s's it's a time!
|
|
137
|
-
format.scan(/[hms]+/).length > 1
|
|
138
|
-
end
|
|
139
121
|
end
|
|
140
122
|
end
|
|
@@ -13,25 +13,33 @@ module Xsv
|
|
|
13
13
|
def initialize(&block)
|
|
14
14
|
@block = block
|
|
15
15
|
@state = nil
|
|
16
|
+
@skip = false
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
def start_element(name, _attrs)
|
|
19
20
|
case name
|
|
20
21
|
when 'si'
|
|
21
22
|
@current_string = ''
|
|
23
|
+
@skip = false
|
|
24
|
+
when 'rPh'
|
|
25
|
+
@skip = true
|
|
22
26
|
when 't'
|
|
23
27
|
@state = name
|
|
24
28
|
end
|
|
25
29
|
end
|
|
26
30
|
|
|
27
31
|
def characters(value)
|
|
28
|
-
|
|
32
|
+
if @state == 't' && !@skip
|
|
33
|
+
@current_string += value
|
|
34
|
+
end
|
|
29
35
|
end
|
|
30
36
|
|
|
31
37
|
def end_element(name)
|
|
32
38
|
case name
|
|
33
39
|
when 'si'
|
|
34
40
|
@block.call(@current_string)
|
|
41
|
+
when 'rPh'
|
|
42
|
+
@skip = false
|
|
35
43
|
when 't'
|
|
36
44
|
@state = nil
|
|
37
45
|
end
|
data/lib/xsv/version.rb
CHANGED
data/lib/xsv/workbook.rb
CHANGED
|
@@ -42,6 +42,8 @@ module Xsv
|
|
|
42
42
|
# trim_empty_rows (false) Scan sheet for end of content and don't return trailing rows
|
|
43
43
|
#
|
|
44
44
|
def initialize(zip, trim_empty_rows: false)
|
|
45
|
+
raise ArgumentError, "Passed argument is not an instance of Zip::File. Did you mean to use Workbook.open?" unless zip.is_a?(Zip::File)
|
|
46
|
+
|
|
45
47
|
@zip = zip
|
|
46
48
|
@trim_empty_rows = trim_empty_rows
|
|
47
49
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: xsv
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Martijn Storck
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-
|
|
11
|
+
date: 2021-05-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rubyzip
|