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 +5 -5
- data/.travis.yml +3 -2
- data/CHANGELOG.md +4 -0
- data/README.md +12 -5
- data/lib/simple_xlsx_reader/version.rb +1 -1
- data/lib/simple_xlsx_reader.rb +14 -7
- data/test/simple_xlsx_reader_test.rb +57 -19
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e2b04473235c5ed2c2764f62a627fa6f16816c36e0fcff3497be229f8666a0f7
|
4
|
+
data.tar.gz: 9367b0082f31e9cb208d9f97ed6cb67d5276a459562809460694602339dfdaad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd42f7a0b8830a2f01703dca10ae779b973566ad25e3b74d31dc3693977fa5b2b3442e47bc1a3b50723bae3bb9f31facd923f1eaba06b51cc8b927e7fb207cf3
|
7
|
+
data.tar.gz: 38ecb026b0ad5a1985d88349a839a9d2972f85596504e6f300686f9751169a3c8d62582e79119106085a9cadc066517206da117993c3a30f48a5a0c58f256b4c
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
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 :
|
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
|
-
|
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(
|
64
|
+
Xml.load(string_or_io)
|
58
65
|
end
|
59
66
|
|
60
67
|
class Sheet < Struct.new(:name, :rows)
|
data/lib/simple_xlsx_reader.rb
CHANGED
@@ -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 :
|
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
|
-
|
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(
|
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(
|
108
|
+
def self.load(string_or_io)
|
102
109
|
self.new.tap do |xml|
|
103
|
-
SimpleXlsxReader::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(:
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
"
|
16
|
-
[
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
+
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:
|
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
|
-
|
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
|