xsv 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +3 -1
- data/lib/xsv/sax_parser.rb +10 -12
- data/lib/xsv/sheet.rb +5 -4
- data/lib/xsv/sheet_bounds_handler.rb +1 -1
- data/lib/xsv/styles_handler.rb +3 -2
- data/lib/xsv/version.rb +1 -1
- data/lib/xsv/workbook.rb +12 -1
- 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: 85395cd1f83157097328c94eb82db6ecbf4c3e18ae1241c56762b21d5de03927
|
4
|
+
data.tar.gz: 3141ce4b9bd703aed15cab002f6905636d3597a92492e7d7689077628b7618b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91870ea588f4fbe857c7c8a75c0282a8a22dd91c552bb166cda59d6ecffb32694383dd764136f8412dcaffa12d177df15cd73d408a84d7553ed9d83074c5af46
|
7
|
+
data.tar.gz: e9c81c6c5601b290d13d8eea15a57c018c7c6cee064bd478026b82d279b28d29e7f30d0fe9703e46d16c9653697f71454714592fc9f05ac105836598b7cd4176
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Xsv Changelog
|
2
2
|
|
3
|
+
## 1.0.1 2021-03-18
|
4
|
+
|
5
|
+
- Allow passing a block to Workbook.open
|
6
|
+
- `parse_headers!` returns self to allow chaining (thanks @senhalil)
|
7
|
+
|
3
8
|
## 1.0.0 2021-01-26
|
4
9
|
|
5
10
|
- Xsv no longer depends on native extensions, thanks to a pure-Ruby XML parser
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Travis CI](https://img.shields.io/travis/martijn/xsv/master)](https://travis-ci.org/martijn/xsv)
|
4
4
|
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/github/martijn/xsv)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/xsv.svg)](https://badge.fury.io/rb/xsv)
|
5
6
|
|
6
7
|
Xsv is a fast, lightweight, pure Ruby parser for Office Open XML spreadsheet files
|
7
8
|
(commonly known as Excel or .xlsx files). It strives to be minimal in the
|
@@ -82,7 +83,8 @@ sheet[1] # => {"header1" => "value1", "header2" => "value2"}
|
|
82
83
|
Be aware that hash mode will lead to unpredictable results if the worksheet
|
83
84
|
has multiple columns with the same header.
|
84
85
|
|
85
|
-
`Xsv::Workbook.open` accepts a filename, or an IO or String containing a workbook.
|
86
|
+
`Xsv::Workbook.open` accepts a filename, or an IO or String containing a workbook. Optionally, you can pass a block
|
87
|
+
which will be called with the workbook as parameter, like `File#open`.
|
86
88
|
|
87
89
|
`Xsv::Sheet` implements `Enumerable` so you can call methods like `#first`,
|
88
90
|
`#filter`/`#select`, and `#map` on it.
|
data/lib/xsv/sax_parser.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Xsv
|
4
4
|
class SaxParser
|
5
|
-
ATTR_REGEX = /((\S+)="(.*?)")/m
|
5
|
+
ATTR_REGEX = /((\S+)="(.*?)")/m
|
6
6
|
|
7
7
|
def parse(io)
|
8
8
|
state = :look_start
|
@@ -34,11 +34,11 @@ module Xsv
|
|
34
34
|
|
35
35
|
if respond_to?(:characters) && !chars.empty?
|
36
36
|
if chars.index('&')
|
37
|
-
chars.gsub!('&',
|
38
|
-
chars.gsub!(''',
|
39
|
-
chars.gsub!('>',
|
40
|
-
chars.gsub!('<',
|
41
|
-
chars.gsub!('"',
|
37
|
+
chars.gsub!('&', '&')
|
38
|
+
chars.gsub!(''', "'")
|
39
|
+
chars.gsub!('>', '>')
|
40
|
+
chars.gsub!('<', '<')
|
41
|
+
chars.gsub!('"', '"')
|
42
42
|
end
|
43
43
|
characters(chars)
|
44
44
|
end
|
@@ -66,13 +66,11 @@ module Xsv
|
|
66
66
|
|
67
67
|
if tag_name.start_with?('/')
|
68
68
|
end_element(tag_name[1..-1]) if respond_to?(:end_element)
|
69
|
+
elsif args.nil?
|
70
|
+
start_element(tag_name, nil)
|
69
71
|
else
|
70
|
-
|
71
|
-
|
72
|
-
else
|
73
|
-
start_element(tag_name, args.scan(ATTR_REGEX).each_with_object({}) { |m, h| h[m[1].to_sym] = m[2] })
|
74
|
-
end_element(tag_name) if args.end_with?('/') && respond_to?(:end_element)
|
75
|
-
end
|
72
|
+
start_element(tag_name, args.scan(ATTR_REGEX).each_with_object({}) { |m, h| h[m[1].to_sym] = m[2] })
|
73
|
+
end_element(tag_name) if args.end_with?('/') && respond_to?(:end_element)
|
76
74
|
end
|
77
75
|
|
78
76
|
state = :look_start
|
data/lib/xsv/sheet.rb
CHANGED
@@ -80,12 +80,12 @@ module Xsv
|
|
80
80
|
|
81
81
|
# Load headers in the top row of the worksheet. After parsing of headers
|
82
82
|
# all methods return hashes instead of arrays
|
83
|
-
# @return [
|
83
|
+
# @return [self]
|
84
84
|
def parse_headers!
|
85
85
|
@headers = parse_headers
|
86
86
|
@mode = :hash
|
87
87
|
|
88
|
-
|
88
|
+
self
|
89
89
|
end
|
90
90
|
|
91
91
|
# Return the headers of the sheet as an array
|
@@ -100,9 +100,10 @@ module Xsv
|
|
100
100
|
private
|
101
101
|
|
102
102
|
def parse_headers
|
103
|
-
|
103
|
+
case @mode
|
104
|
+
when :array
|
104
105
|
first
|
105
|
-
|
106
|
+
when :hash
|
106
107
|
@mode = :array
|
107
108
|
headers.tap { @mode = :hash }
|
108
109
|
end || []
|
data/lib/xsv/styles_handler.rb
CHANGED
data/lib/xsv/version.rb
CHANGED
data/lib/xsv/workbook.rb
CHANGED
@@ -22,6 +22,16 @@ module Xsv
|
|
22
22
|
else # must be a filename
|
23
23
|
new(Zip::File.open(data), **kws)
|
24
24
|
end
|
25
|
+
|
26
|
+
if block_given?
|
27
|
+
begin
|
28
|
+
yield(@workbook)
|
29
|
+
ensure
|
30
|
+
@workbook.close
|
31
|
+
end
|
32
|
+
else
|
33
|
+
@workbook
|
34
|
+
end
|
25
35
|
end
|
26
36
|
|
27
37
|
# Open a workbook from an instance of {Zip::File}. Generally it's recommended
|
@@ -52,6 +62,7 @@ module Xsv
|
|
52
62
|
# @return [true]
|
53
63
|
def close
|
54
64
|
@zip.close
|
65
|
+
@zip = nil
|
55
66
|
@sheets = nil
|
56
67
|
@xfs = nil
|
57
68
|
@numFmts = nil
|
@@ -78,7 +89,7 @@ module Xsv
|
|
78
89
|
stream = handle.get_input_stream
|
79
90
|
SharedStringsParser.parse(stream)
|
80
91
|
ensure
|
81
|
-
stream
|
92
|
+
stream&.close
|
82
93
|
end
|
83
94
|
|
84
95
|
def fetch_styles
|
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.1
|
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-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|