xsv 1.1.1 → 1.2.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 +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +10 -7
- data/lib/xsv/sax_parser.rb +3 -8
- data/lib/xsv/shared_strings_parser.rb +1 -1
- data/lib/xsv/sheet.rb +6 -0
- data/lib/xsv/sheet_rows_handler.rb +1 -1
- data/lib/xsv/version.rb +1 -1
- data/lib/xsv.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: 58e5d405e39f42d0e5287d47dd65c65b39a0ab5a2fc7fde3fd85c7211469e6e1
|
|
4
|
+
data.tar.gz: 7100a73ce192536f81a34ffbb1b431a793edf9cb71c1612a547a64a686a8330f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3b8fcbab2e2aa1f02dc0b51051a9b60dd2518b18b72007c2f3e77fa99248e864069d54b0bb43d783f8bb6ef79b6c2504c8cd05c244a2e9c85cddb882de224556
|
|
7
|
+
data.tar.gz: 3ec5120d8b6e365996985c75f4c291e3f4805e9876fd93ae2dfe071c5bd69ad751677cf71121ac23f6e9bed75ab80296b12346d79696cb6105974345d289bb7e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Xsv Changelog
|
|
2
2
|
|
|
3
|
+
## 1.2.0 2023-01-01
|
|
4
|
+
|
|
5
|
+
**This release contains the following minor breaking changes**
|
|
6
|
+
|
|
7
|
+
- Raise an error when entering hash mode on a sheet with duplicate headers to prevent unintentional behaviour (fixes #44)
|
|
8
|
+
- Xsv now returns frozen strings to further improve performance. This means it's no longer possible to call mutating methods on strings read from worksheets without unfreezing them first.
|
|
9
|
+
- Unescape all HTML entities in XML characters (thanks @til)
|
|
10
|
+
|
|
3
11
|
## 1.1.1 2022-04-01
|
|
4
12
|
|
|
5
13
|
- Improve compatibility with files generated by the Open XML SDK (#40)
|
|
@@ -119,4 +127,4 @@ Fix a Gemfile small Gemfile issue that broke the 0.3.3 and 0.3.4 releases
|
|
|
119
127
|
|
|
120
128
|
## 0.3.3 - 2020-03-02
|
|
121
129
|
|
|
122
|
-
|
|
130
|
+
Initial version with a changelog and reasonably complete YARD documentation.
|
data/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# Xsv .xlsx reader
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
[](https://github.com/martijn/xsv/actions/workflows/ruby.yml)
|
|
5
6
|
[](https://app.codecov.io/gh/martijn/xsv)
|
|
6
7
|
[](https://rubydoc.info/github/martijn/xsv)
|
|
7
8
|
[](https://badge.fury.io/rb/xsv)
|
|
@@ -36,10 +37,9 @@ Or install it yourself as:
|
|
|
36
37
|
|
|
37
38
|
$ gem install xsv
|
|
38
39
|
|
|
39
|
-
Xsv targets ruby >= 2.
|
|
40
|
-
tested successfully with MRI, JRuby, and TruffleRuby.
|
|
41
|
-
|
|
42
|
-
when that becomes stable.
|
|
40
|
+
Xsv targets ruby >= 2.6 and has a just single dependency, `rubyzip`. It has been
|
|
41
|
+
tested successfully with MRI, JRuby, and TruffleRuby. It has no native extensions
|
|
42
|
+
and is designed to be thread-safe.
|
|
43
43
|
|
|
44
44
|
## Usage
|
|
45
45
|
|
|
@@ -85,8 +85,11 @@ sheet.parse_headers!
|
|
|
85
85
|
sheet[0] # => {"header1" => "value1", "header2" => "value2"}
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
Because of the way Ruby hashes work will raise `Xsv::DuplicateHeaders` if it detects
|
|
89
|
+
duplicate values in the header row when calling `#parse_headers!` or when opening
|
|
90
|
+
a workbook with `parse_headers: true`.
|
|
91
|
+
|
|
92
|
+
`Xsv::Sheet` implements `Enumerable` so along with `#each`
|
|
90
93
|
you can call methods like `#first`, `#filter`/`#select`, and `#map` on it.
|
|
91
94
|
|
|
92
95
|
### Opening a string or buffer instead of filename
|
data/lib/xsv/sax_parser.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "cgi"
|
|
4
|
+
|
|
3
5
|
module Xsv
|
|
4
6
|
class SaxParser
|
|
5
7
|
ATTR_REGEX = /((\p{Alnum}+)="(.*?)")/mn
|
|
@@ -36,14 +38,7 @@ module Xsv
|
|
|
36
38
|
chars = pbuf.slice!(0, o + 1).chop!.force_encoding("utf-8")
|
|
37
39
|
|
|
38
40
|
if responds_to_characters && !chars.empty?
|
|
39
|
-
|
|
40
|
-
chars.gsub!("&", "&")
|
|
41
|
-
chars.gsub!("'", "'")
|
|
42
|
-
chars.gsub!(">", ">")
|
|
43
|
-
chars.gsub!("<", "<")
|
|
44
|
-
chars.gsub!(""", '"')
|
|
45
|
-
end
|
|
46
|
-
characters(chars)
|
|
41
|
+
characters(CGI.unescapeHTML(chars))
|
|
47
42
|
end
|
|
48
43
|
|
|
49
44
|
state = :look_end
|
data/lib/xsv/sheet.rb
CHANGED
|
@@ -83,6 +83,12 @@ module Xsv
|
|
|
83
83
|
# @return [self]
|
|
84
84
|
def parse_headers!
|
|
85
85
|
@headers = parse_headers
|
|
86
|
+
|
|
87
|
+
# Check for duplicate headers, but don't care about nil columns
|
|
88
|
+
if (duplicate_header = @headers.detect { |h| @headers.count(h) > 1 })
|
|
89
|
+
raise Xsv::DuplicateHeaders, "Duplicate header '#{duplicate_header}' found, consider parsing this sheet in array mode."
|
|
90
|
+
end
|
|
91
|
+
|
|
86
92
|
@mode = :hash
|
|
87
93
|
|
|
88
94
|
self
|
data/lib/xsv/version.rb
CHANGED
data/lib/xsv.rb
CHANGED
|
@@ -21,6 +21,8 @@ require "xsv/workbook"
|
|
|
21
21
|
module Xsv
|
|
22
22
|
class Error < StandardError; end
|
|
23
23
|
|
|
24
|
+
class DuplicateHeaders < StandardError; end
|
|
25
|
+
|
|
24
26
|
# An AssertionFailed error indicates an unexpected condition, meaning a bug
|
|
25
27
|
# or misinterpreted .xlsx document
|
|
26
28
|
class AssertionFailed < StandardError; end
|
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.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Martijn Storck
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2023-01-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rubyzip
|