simple_xlsx_reader 2.0.0 → 2.0.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 +4 -4
- data/.github/workflows/ruby.yml +2 -5
- data/CHANGELOG.md +5 -0
- data/lib/simple_xlsx_reader/document.rb +6 -4
- data/lib/simple_xlsx_reader/loader.rb +4 -4
- data/lib/simple_xlsx_reader/version.rb +1 -1
- data/lib/simple_xlsx_reader.rb +5 -2
- data/test/simple_xlsx_reader_test.rb +9 -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: 20c74bef372629ffb807d50df274c90682e17d53eed296a1e05fbb99533d4a8e
|
|
4
|
+
data.tar.gz: 9c4311913e79ad139414a4fe064d89fb246a1d46f30b7736c87f049985801660
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 18db8595a36d4d9bb0f1dfee5da58753b799a6358530dfb9436f9c7b72e8e06bb9101d86d8dc617669c075fced44db8c24fdca6c5a3b2cb6b908cc0cd645eeb1
|
|
7
|
+
data.tar.gz: 23d4b057060c5f66ad3d57d0d65fa6e127ed4c7faa622ec0d236b58dd439179b41dff041ec2dd955c2ec893d577d9660465d2dcea0fe9a9f3af5e911ac5aa8e7
|
data/.github/workflows/ruby.yml
CHANGED
|
@@ -22,15 +22,12 @@ jobs:
|
|
|
22
22
|
runs-on: ubuntu-latest
|
|
23
23
|
strategy:
|
|
24
24
|
matrix:
|
|
25
|
-
ruby-version: ['2.6', '2.7', '3.0']
|
|
25
|
+
ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2']
|
|
26
26
|
|
|
27
27
|
steps:
|
|
28
28
|
- uses: actions/checkout@v3
|
|
29
29
|
- name: Set up Ruby
|
|
30
|
-
|
|
31
|
-
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
|
32
|
-
# uses: ruby/setup-ruby@v1
|
|
33
|
-
uses: ruby/setup-ruby@2b019609e2b0f1ea1a2bc8ca11cb82ab46ada124
|
|
30
|
+
uses: ruby/setup-ruby@v1
|
|
34
31
|
with:
|
|
35
32
|
ruby-version: ${{ matrix.ruby-version }}
|
|
36
33
|
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
data/CHANGELOG.md
CHANGED
|
@@ -8,14 +8,16 @@ module SimpleXlsxReader
|
|
|
8
8
|
# Main class for the public API. See the README for usage examples,
|
|
9
9
|
# or read the code, it's pretty friendly.
|
|
10
10
|
class Document
|
|
11
|
-
attr_reader :
|
|
11
|
+
attr_reader :string_or_io
|
|
12
12
|
|
|
13
|
-
def initialize(file_path)
|
|
14
|
-
|
|
13
|
+
def initialize(legacy_file_path = nil, file_path: nil, string_or_io: nil)
|
|
14
|
+
fail(ArgumentError, 'either file_path or string_or_io must be provided') if legacy_file_path.nil? && file_path.nil? && string_or_io.nil?
|
|
15
|
+
|
|
16
|
+
@string_or_io = string_or_io || File.new(legacy_file_path || file_path)
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
def sheets
|
|
18
|
-
@sheets ||= Loader.new(
|
|
20
|
+
@sheets ||= Loader.new(string_or_io).init_sheets
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
# Expensive because it slurps all the sheets into memory,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module SimpleXlsxReader
|
|
4
|
-
class Loader < Struct.new(:
|
|
4
|
+
class Loader < Struct.new(:string_or_io)
|
|
5
5
|
attr_accessor :shared_strings, :sheet_parsers, :sheet_toc, :style_types, :base_date
|
|
6
6
|
|
|
7
7
|
def init_sheets
|
|
8
8
|
ZipReader.new(
|
|
9
|
-
|
|
9
|
+
string_or_io: string_or_io,
|
|
10
10
|
loader: self
|
|
11
11
|
).read
|
|
12
12
|
|
|
@@ -19,12 +19,12 @@ module SimpleXlsxReader
|
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
ZipReader = Struct.new(:
|
|
22
|
+
ZipReader = Struct.new(:string_or_io, :loader, keyword_init: true) do
|
|
23
23
|
attr_reader :zip
|
|
24
24
|
|
|
25
25
|
def initialize(*args)
|
|
26
26
|
super
|
|
27
|
-
@zip = SimpleXlsxReader::Zip.
|
|
27
|
+
@zip = SimpleXlsxReader::Zip.open_buffer(string_or_io)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def read
|
data/lib/simple_xlsx_reader.rb
CHANGED
|
@@ -42,8 +42,11 @@ module SimpleXlsxReader
|
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def open(file_path)
|
|
45
|
-
Document.new(file_path).tap(&:sheets)
|
|
45
|
+
Document.new(file_path: file_path).tap(&:sheets)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def parse(string_or_io)
|
|
49
|
+
Document.new(string_or_io: string_or_io).tap(&:sheets)
|
|
46
50
|
end
|
|
47
|
-
alias parse open
|
|
48
51
|
end
|
|
49
52
|
end
|
|
@@ -18,6 +18,7 @@ describe SimpleXlsxReader do
|
|
|
18
18
|
|
|
19
19
|
let(:sesame_street_blog_file_path) { File.join(File.dirname(__FILE__), 'sesame_street_blog.xlsx') }
|
|
20
20
|
let(:sesame_street_blog_io) { File.new(sesame_street_blog_file_path) }
|
|
21
|
+
let(:sesame_street_blog_string) { IO.read(sesame_street_blog_file_path) }
|
|
21
22
|
|
|
22
23
|
let(:expected_result) do
|
|
23
24
|
{
|
|
@@ -54,6 +55,14 @@ describe SimpleXlsxReader do
|
|
|
54
55
|
end
|
|
55
56
|
end
|
|
56
57
|
|
|
58
|
+
describe 'load from string' do
|
|
59
|
+
let(:subject) { SimpleXlsxReader.parse(sesame_street_blog_io) }
|
|
60
|
+
|
|
61
|
+
it 'reads an xlsx string into a hash of {[sheet name] => [data]}' do
|
|
62
|
+
_(subject.to_hash).must_equal(expected_result)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
57
66
|
it 'outputs strings in UTF-8 encoding' do
|
|
58
67
|
document = SimpleXlsxReader.parse(sesame_street_blog_io)
|
|
59
68
|
_(document.sheets[0].rows.to_a.flatten.map(&:encoding).uniq)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simple_xlsx_reader
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Woody Peterson
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2023-03-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: nokogiri
|