simple_xlsx_reader 1.0.4 → 1.0.5

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
- SHA1:
3
- metadata.gz: 1dd4b96753ca2dafcfadf59469c3a9357742ab7e
4
- data.tar.gz: ffb23c6b020a55b893743206c236fea2abb07b65
2
+ SHA256:
3
+ metadata.gz: e2b04473235c5ed2c2764f62a627fa6f16816c36e0fcff3497be229f8666a0f7
4
+ data.tar.gz: 9367b0082f31e9cb208d9f97ed6cb67d5276a459562809460694602339dfdaad
5
5
  SHA512:
6
- metadata.gz: 01a2326f942c455c665d5c135aa4115edd87a307e4aa5dff5e1d177ef61dcd326bcc33ad342f3b164ac7996731f0e31e97a9471973b98682757624f44052f6a2
7
- data.tar.gz: b5371713dd232d5f1134ab810ea69447a3ad59bb781f917df2bc3a49e7b1c86c765ab0a074b1ddce021390f1b1d54e1507326abf22a65f1d83de1cf568ce7896
6
+ metadata.gz: cd42f7a0b8830a2f01703dca10ae779b973566ad25e3b74d31dc3693977fa5b2b3442e47bc1a3b50723bae3bb9f31facd923f1eaba06b51cc8b927e7fb207cf3
7
+ data.tar.gz: 38ecb026b0ad5a1985d88349a839a9d2972f85596504e6f300686f9751169a3c8d62582e79119106085a9cadc066517206da117993c3a30f48a5a0c58f256b4c
data/.travis.yml CHANGED
@@ -3,5 +3,6 @@ cache: bundler
3
3
  before_install:
4
4
  - gem update bundler
5
5
  rvm:
6
- - 1.9.3
7
- - 2.3.0
6
+ - 2.5.8
7
+ - 2.7.2
8
+ - 3.0.0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 1.0.5
2
+
3
+ * Support string or io input via `SimpleXlsxReader#parse` (@kalsan, @til)
4
+
1
5
  ### 1.0.4
2
6
 
3
7
  * Fix Windows + RubyZip 1.2.1 bug preventing files from being read
data/README.md CHANGED
@@ -35,14 +35,21 @@ Here's the totality of the public api, in code:
35
35
 
36
36
  module SimpleXlsxReader
37
37
  def self.open(file_path)
38
- Document.new(file_path).tap(&:sheets)
38
+ Document.new(file_path: file_path).tap(&:sheets)
39
+ end
40
+
41
+ def self.parse(string_or_io)
42
+ Document.new(string_or_io: string_or_io).tap(&:sheets)
39
43
  end
40
44
 
41
45
  class Document
42
- attr_reader :file_path
46
+ attr_reader :string_or_io
47
+
48
+ def initialize(legacy_file_path = nil, file_path: nil, string_or_io: nil)
49
+ ((file_path || legacy_file_path).nil? ^ string_or_io.nil?) ||
50
+ fail(ArgumentError, 'either file_path or string_or_io must be provided')
43
51
 
44
- def initialize(file_path)
45
- @file_path = file_path
52
+ @string_or_io = string_or_io || File.new(file_path || legacy_file_path)
46
53
  end
47
54
 
48
55
  def sheets
@@ -54,7 +61,7 @@ Here's the totality of the public api, in code:
54
61
  end
55
62
 
56
63
  def xml
57
- Xml.load(file_path)
64
+ Xml.load(string_or_io)
58
65
  end
59
66
 
60
67
  class Sheet < Struct.new(:name, :rows)
@@ -1,3 +1,3 @@
1
1
  module SimpleXlsxReader
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -53,14 +53,21 @@ module SimpleXlsxReader
53
53
  end
54
54
 
55
55
  def self.open(file_path)
56
- Document.new(file_path).tap(&:sheets)
56
+ Document.new(file_path: file_path).tap(&:sheets)
57
+ end
58
+
59
+ def self.parse(string_or_io)
60
+ Document.new(string_or_io: string_or_io).tap(&:sheets)
57
61
  end
58
62
 
59
63
  class Document
60
- attr_reader :file_path
64
+ attr_reader :string_or_io
65
+
66
+ def initialize(legacy_file_path = nil, file_path: nil, string_or_io: nil)
67
+ ((file_path || legacy_file_path).nil? ^ string_or_io.nil?) ||
68
+ fail(ArgumentError, 'either file_path or string_or_io must be provided')
61
69
 
62
- def initialize(file_path)
63
- @file_path = file_path
70
+ @string_or_io = string_or_io || File.new(file_path || legacy_file_path)
64
71
  end
65
72
 
66
73
  def sheets
@@ -72,7 +79,7 @@ module SimpleXlsxReader
72
79
  end
73
80
 
74
81
  def xml
75
- Xml.load(file_path)
82
+ Xml.load(string_or_io)
76
83
  end
77
84
 
78
85
  class Sheet < Struct.new(:name, :rows)
@@ -98,9 +105,9 @@ module SimpleXlsxReader
98
105
  class Xml
99
106
  attr_accessor :workbook, :shared_strings, :sheets, :sheet_rels, :styles
100
107
 
101
- def self.load(file_path)
108
+ def self.load(string_or_io)
102
109
  self.new.tap do |xml|
103
- SimpleXlsxReader::Zip.open(file_path) do |zip|
110
+ SimpleXlsxReader::Zip.open_buffer(string_or_io) do |zip|
104
111
  xml.sheets = []
105
112
  xml.sheet_rels = []
106
113
 
@@ -4,25 +4,63 @@ require 'time'
4
4
  SXR = SimpleXlsxReader
5
5
 
6
6
  describe SimpleXlsxReader do
7
- let(:sesame_street_blog_file) { File.join(File.dirname(__FILE__),
8
- 'sesame_street_blog.xlsx') }
9
-
10
- let(:subject) { SimpleXlsxReader::Document.new(sesame_street_blog_file) }
11
-
12
- describe '#to_hash' do
13
- it 'reads an xlsx file into a hash of {[sheet name] => [data]}' do
14
- subject.to_hash.must_equal({
15
- "Authors"=>
16
- [["Name", "Occupation"],
17
- ["Big Bird", "Teacher"]],
18
-
19
- "Posts"=>
20
- [["Author Name", "Title", "Body", "Created At", "Comment Count", "URL"],
21
- ["Big Bird", "The Number 1", "The Greatest", Time.parse("2002-01-01 11:00:00 UTC"), 1, SXR::Hyperlink.new("http://www.example.com/hyperlink-function", "This uses the HYPERLINK() function")],
22
- ["Big Bird", "The Number 2", "Second Best", Time.parse("2002-01-02 14:00:00 UTC"), 2, SXR::Hyperlink.new("http://www.example.com/hyperlink-gui", "This uses the hyperlink GUI option")],
23
- ["Big Bird", "Formula Dates", "Tricky tricky", Time.parse("2002-01-03 14:00:00 UTC"), 0, nil],
24
- ["Empty Eagress", nil, "The title, date, and comment have types, but no values", nil, nil, nil]]
25
- })
7
+ let(:sesame_street_blog_file_path) { File.join(File.dirname(__FILE__), 'sesame_street_blog.xlsx') }
8
+ let(:sesame_street_blog_io) { File.new(sesame_street_blog_file_path) }
9
+ let(:expected_result) do
10
+ {
11
+ "Authors"=>
12
+ [["Name", "Occupation"],
13
+ ["Big Bird", "Teacher"]],
14
+ "Posts"=>
15
+ [["Author Name", "Title", "Body", "Created At", "Comment Count", "URL"],
16
+ ["Big Bird", "The Number 1", "The Greatest", Time.parse("2002-01-01 11:00:00 UTC"), 1, SXR::Hyperlink.new("http://www.example.com/hyperlink-function", "This uses the HYPERLINK() function")],
17
+ ["Big Bird", "The Number 2", "Second Best", Time.parse("2002-01-02 14:00:00 UTC"), 2, SXR::Hyperlink.new("http://www.example.com/hyperlink-gui", "This uses the hyperlink GUI option")],
18
+ ["Big Bird", "Formula Dates", "Tricky tricky", Time.parse("2002-01-03 14:00:00 UTC"), 0, nil],
19
+ ["Empty Eagress", nil, "The title, date, and comment have types, but no values", nil, nil, nil]]
20
+ }
21
+ end
22
+
23
+ describe SimpleXlsxReader do
24
+ describe 'load from file path' do
25
+ let(:subject) { SimpleXlsxReader.open(sesame_street_blog_file_path) }
26
+
27
+ it 'reads an xlsx file into a hash of {[sheet name] => [data]}' do
28
+ subject.to_hash.must_equal(expected_result)
29
+ end
30
+ end
31
+
32
+ describe 'load from buffer' do
33
+ let(:subject) { SimpleXlsxReader.parse(sesame_street_blog_io) }
34
+
35
+ it 'reads an xlsx buffer into a hash of {[sheet name] => [data]}' do
36
+ subject.to_hash.must_equal(expected_result)
37
+ end
38
+ end
39
+ end
40
+
41
+ describe SimpleXlsxReader::Document do
42
+ describe 'load from file path' do
43
+ let(:subject) { SimpleXlsxReader::Document.new(file_path: sesame_street_blog_file_path) }
44
+
45
+ it 'reads an xlsx file into a hash of {[sheet name] => [data]}' do
46
+ subject.to_hash.must_equal(expected_result)
47
+ end
48
+ end
49
+
50
+ describe 'load from buffer' do
51
+ let(:subject) { SimpleXlsxReader::Document.new(string_or_io: sesame_street_blog_io) }
52
+
53
+ it 'reads an xlsx buffer into a hash of {[sheet name] => [data]}' do
54
+ subject.to_hash.must_equal(expected_result)
55
+ end
56
+ end
57
+
58
+ describe 'load from file path (legacy API)' do
59
+ let(:subject) { SimpleXlsxReader::Document.new(sesame_street_blog_file_path) }
60
+
61
+ it 'reads an xlsx file into a hash of {[sheet name] => [data]}' do
62
+ subject.to_hash.must_equal(expected_result)
63
+ end
26
64
  end
27
65
  end
28
66
 
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: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Woody Peterson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-12 00:00:00.000000000 Z
11
+ date: 2022-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -130,8 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  requirements: []
133
- rubyforge_project:
134
- rubygems_version: 2.5.2
133
+ rubygems_version: 3.1.6
135
134
  signing_key:
136
135
  specification_version: 4
137
136
  summary: Read xlsx data the Ruby way