xsv 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85395cd1f83157097328c94eb82db6ecbf4c3e18ae1241c56762b21d5de03927
4
- data.tar.gz: 3141ce4b9bd703aed15cab002f6905636d3597a92492e7d7689077628b7618b9
3
+ metadata.gz: 6433d19ba65e00b98adecde398a3bfbfe9583ac811290d8f8ffa5ada16ea9b70
4
+ data.tar.gz: 903c61f9485f1380a064cc8ccfdfa378a46df1383259e6c82ca21501dcc485a5
5
5
  SHA512:
6
- metadata.gz: 91870ea588f4fbe857c7c8a75c0282a8a22dd91c552bb166cda59d6ecffb32694383dd764136f8412dcaffa12d177df15cd73d408a84d7553ed9d83074c5af46
7
- data.tar.gz: e9c81c6c5601b290d13d8eea15a57c018c7c6cee064bd478026b82d279b28d29e7f30d0fe9703e46d16c9653697f71454714592fc9f05ac105836598b7cd4176
6
+ metadata.gz: e79c5866cd7dd20f0c36ea46a341234bcbc8cdbed40492c8bab31543fe96fcd4bd242a6c63368841e7ad481e4f72187eca5682effdb445388256e83969e1a969
7
+ data.tar.gz: 474da420765253453a3a1e9a25e8a2582052600bfdaee3e0f246db9d6b415a2a2ae46bd9c2edbb5364efb99708061125f189fd608cab5122bfc2090dd183004d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Xsv Changelog
2
2
 
3
+ ## 1.0.2 2021-05-01
4
+
5
+ - Ignore phonetic shared string data (thanks @sinoue-1003)
6
+ - Throw ArgumentError when `Workbook.new` is called unintentionally
7
+
3
8
  ## 1.0.1 2021-03-18
4
9
 
5
10
  - Allow passing a block to Workbook.open
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) if number.is_a?(String)
106
+ number = parse_number(number) # number is always a string since it comes out of the Sax Parser
107
107
 
108
- if datetime_format?(format)
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 date_format?(format)
115
+ elsif is_date_format
111
116
  parse_date(number)
112
- elsif time_format?(format)
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
- @current_string += value if @state == 't'
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Xsv
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.2'
5
5
  end
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.1
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-03-18 00:00:00.000000000 Z
11
+ date: 2021-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip