simple_xlsx_reader 2.0.0 → 2.0.1

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: 979490ce3bd7f0482879fb5fb5465e10ad1b07c1488d0a544950131d9063050a
4
- data.tar.gz: 412d0040a586cc5ee4acdd4a2f74dd74f3bf9eb781a35d8a36c12f6caadc566c
3
+ metadata.gz: 20c74bef372629ffb807d50df274c90682e17d53eed296a1e05fbb99533d4a8e
4
+ data.tar.gz: 9c4311913e79ad139414a4fe064d89fb246a1d46f30b7736c87f049985801660
5
5
  SHA512:
6
- metadata.gz: 00c01bc0c2a393eb35e458411dfeab55b8bf30cee2661324cbd97a175baf0ceb31a881b1b2b7bd668a2b475ff008372c1428908340e30769308884355fdd46e8
7
- data.tar.gz: 81b1b26806a97c56710cab64aa22212985dea82b308e2fbba6835f4ea7a69b79067268bb13537999594dc5722928f1df235938355a7d4a51b58ae7ed4af1d093
6
+ metadata.gz: 18db8595a36d4d9bb0f1dfee5da58753b799a6358530dfb9436f9c7b72e8e06bb9101d86d8dc617669c075fced44db8c24fdca6c5a3b2cb6b908cc0cd645eeb1
7
+ data.tar.gz: 23d4b057060c5f66ad3d57d0d65fa6e127ed4c7faa622ec0d236b58dd439179b41dff041ec2dd955c2ec893d577d9660465d2dcea0fe9a9f3af5e911ac5aa8e7
@@ -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
- # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
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
@@ -1,3 +1,8 @@
1
+ ### 2.0.1
2
+
3
+ * Restore ability to parse IO strings (@robbevp)
4
+ * Add Ruby 3.1 and 3.2 to CI (@taichi-ishitani)
5
+
1
6
  ### 2.0.0
2
7
 
3
8
  * SPEED
@@ -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 :file_path
11
+ attr_reader :string_or_io
12
12
 
13
- def initialize(file_path)
14
- @file_path = file_path
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(file_path).init_sheets
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(:file_path)
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
- file_path: file_path,
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(:file_path, :loader, keyword_init: true) do
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.open(file_path)
27
+ @zip = SimpleXlsxReader::Zip.open_buffer(string_or_io)
28
28
  end
29
29
 
30
30
  def read
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleXlsxReader
4
- VERSION = '2.0.0'
4
+ VERSION = '2.0.1'
5
5
  end
@@ -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.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: 2022-08-18 00:00:00.000000000 Z
11
+ date: 2023-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri