xsv 1.1.0 → 1.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1ebfa4e4778af72a8b295d258d899a5b5d01fd029d1294d54af5e4f1e0de05a
4
- data.tar.gz: aa74ffe0d57eebc12e312bdb42107bc39203cd3a0237f2e2481205c8b3b933c9
3
+ metadata.gz: b2cc530ad96a5351ea6ab8a8b9d0f2ee9df0e1827a98e4244f239b3658bc2145
4
+ data.tar.gz: e286d74163ea3524dfcbd92553c0c4254b667e4ea13adae7468c0d1dc4c8089b
5
5
  SHA512:
6
- metadata.gz: 6ebbb32e48860043bdb0a5d17f6fef525252e8bb01ac63180cd0e749dfbd1b3bb08b8a82e43e9e13da2fa187c02f77e37f525e9c7453334bc3cb8fdf05400187
7
- data.tar.gz: 4e1450daebcc3ddfbc0585de52f4d1f362ef2d79281e59cc641119a47924f8450b76c3643a6403a440e0a581ebfcc108431a311f902e2b48be61a1d2afd7b19e
6
+ metadata.gz: a89e58bc0447ecbd2eefdd81fe978a5e38438296bcce9dbf18b4dbc3fea5d5740016e35237d229fbab8201bb0e71b208ca66858c9d61e85f4d31d729e9048054
7
+ data.tar.gz: 45ddf90be0abe97dcd8aac6b08b9daeac2f68f7634062655efee6f59fbef50c6aad3eb69a461b4f7fcf9dd2751fa735de82e9a0821ec18d2f45cb4bada591698
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Xsv Changelog
2
2
 
3
+ ## 1.1.1 2022-04-01
4
+
5
+ - Improve compatibility with files generated by the Open XML SDK (#40)
6
+
3
7
  ## 1.1.0 2022-02-13
4
8
 
5
9
  - New, shorter `Xsv.open` syntax as a drop-in replacement for `Xsv::Workbook.open`, which is still supported
data/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # Xsv .xlsx reader
2
2
 
3
- [![Travis CI](https://img.shields.io/travis/martijn/xsv/master)](https://travis-ci.org/martijn/xsv)
4
- [![Codecov](https://img.shields.io/codecov/c/github/martijn/xsv/main)](https://app.codecov.io/gh/martijn/xsv)
5
- [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/github/martijn/xsv)
6
- [![Gem Version](https://badge.fury.io/rb/xsv.svg)](https://badge.fury.io/rb/xsv)
3
+
4
+ [![Test badge](https://img.shields.io/github/workflow/status/martijn/xsv/Ruby/main)](https://github.com/martijn/xsv/actions/workflows/ruby.yml)
5
+ [![Codecov badge](https://img.shields.io/codecov/c/github/martijn/xsv/main)](https://app.codecov.io/gh/martijn/xsv)
6
+ [![Yard Docs badge](http://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/github/martijn/xsv)
7
+ [![Gem Version badge](https://badge.fury.io/rb/xsv.svg)](https://badge.fury.io/rb/xsv)
7
8
 
8
9
  Xsv is a fast, lightweight, pure Ruby parser for ISO/IEC 29500 Office Open XML spreadsheet files
9
10
  (commonly known as Excel or .xlsx files). It strives to be minimal in the
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Xsv
4
4
  class SaxParser
5
- ATTR_REGEX = /((\S+)="(.*?)")/m
5
+ ATTR_REGEX = /((\p{Alnum}+)="(.*?)")/mn
6
6
 
7
7
  def parse(io)
8
8
  responds_to_end_element = respond_to?(:end_element)
@@ -67,13 +67,15 @@ module Xsv
67
67
  args = nil
68
68
  end
69
69
 
70
+ stripped_tag_name = strip_namespace(tag_name)
71
+
70
72
  if tag_name.start_with?("/")
71
- end_element(tag_name[1..]) if responds_to_end_element
73
+ end_element(strip_namespace(tag_name[1..])) if responds_to_end_element
72
74
  elsif args.nil?
73
- start_element(tag_name, nil)
75
+ start_element(stripped_tag_name, nil)
74
76
  else
75
- start_element(tag_name, args.scan(ATTR_REGEX).each_with_object({}) { |m, h| h[m[1].to_sym] = m[2] })
76
- end_element(tag_name) if responds_to_end_element && args.end_with?("/")
77
+ start_element(stripped_tag_name, args.scan(ATTR_REGEX).each_with_object({}) { |(_, k, v), h| h[k.to_sym] = v })
78
+ end_element(stripped_tag_name) if responds_to_end_element && args.end_with?("/")
77
79
  end
78
80
 
79
81
  state = :look_start
@@ -85,5 +87,16 @@ module Xsv
85
87
  end
86
88
  end
87
89
  end
90
+
91
+ private
92
+
93
+ # I am not proud of this, but there's simply no need to deal with xmlns for this application ¯\_(ツ)_/¯
94
+ def strip_namespace(tag)
95
+ if (offset = tag.index(":"))
96
+ tag[offset + 1..]
97
+ else
98
+ tag
99
+ end
100
+ end
88
101
  end
89
102
  end
@@ -17,7 +17,7 @@ module Xsv
17
17
  end
18
18
 
19
19
  def start_element(name, attrs)
20
- @block.call(attrs.slice(:name, :sheetId, :state, :'r:id')) if name == "sheet"
20
+ @block.call(attrs.slice(:name, :sheetId, :state, :id)) if name == "sheet"
21
21
  end
22
22
  end
23
23
  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.1.0"
4
+ VERSION = "1.1.1"
5
5
  end
data/lib/xsv/workbook.rb CHANGED
@@ -93,8 +93,11 @@ module Xsv
93
93
  @zip.glob("xl/worksheets/sheet*.xml").sort do |a, b|
94
94
  a.name[/\d+/].to_i <=> b.name[/\d+/].to_i
95
95
  end.map do |entry|
96
- rel = @relationships.detect { |r| entry.name.end_with?(r[:Target]) && r[:Type].end_with?("worksheet") }
97
- sheet_ids = @sheet_ids.detect { |i| i[:"r:id"] == rel[:Id] }
96
+ rel = @relationships.detect do |r|
97
+ entry.name.end_with?(r[:Target].sub(/^\//, "")) && # ignore leading / in some files
98
+ r[:Type].end_with?("worksheet")
99
+ end
100
+ sheet_ids = @sheet_ids.detect { |i| i[:id] == rel[:Id] }
98
101
  Xsv::Sheet.new(self, entry.get_input_stream, entry.size, sheet_ids).tap do |sheet|
99
102
  sheet.parse_headers! if mode == :hash
100
103
  end
data/xsv.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  if spec.respond_to?(:metadata)
22
22
  spec.metadata["homepage_uri"] = spec.homepage
23
23
  spec.metadata["source_code_uri"] = "https://github.com/martijn/xsv"
24
- spec.metadata["changelog_uri"] = "https://github.com/martijn/xsv/CHANGELOG.md"
24
+ spec.metadata["changelog_uri"] = "https://raw.githubusercontent.com/martijn/xsv/main/CHANGELOG.md"
25
25
  else
26
26
  raise "RubyGems 2.0 or newer is required to protect against " \
27
27
  "public gem pushes."
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.1.0
4
+ version: 1.1.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: 2022-02-13 00:00:00.000000000 Z
11
+ date: 2022-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -141,7 +141,7 @@ licenses:
141
141
  metadata:
142
142
  homepage_uri: https://github.com/martijn/xsv
143
143
  source_code_uri: https://github.com/martijn/xsv
144
- changelog_uri: https://github.com/martijn/xsv/CHANGELOG.md
144
+ changelog_uri: https://raw.githubusercontent.com/martijn/xsv/main/CHANGELOG.md
145
145
  post_install_message:
146
146
  rdoc_options: []
147
147
  require_paths: