single_xlsx 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 930f99fd9d1a4815159e3a8ab1562e017b6e3038
4
+ data.tar.gz: b27f9912f03e8df5cf9f803ca44ac8833daddf0e
5
+ SHA512:
6
+ metadata.gz: d14944d226656dda2b476a4388d7a95515e4823eb73d0f1c911f5555366ec139d554081b0622f72a3b2e04b10319cf7a25c1d5f9e82dc61c373a8a170450ec7a
7
+ data.tar.gz: ac0144d2e37c80ad628abc44990d6e8b1f4069dfa717c46e7c39629125e613450d90832f8f97753c7d39ddc3078792285699c9227756718198b0e830451b865d
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.1.4
5
+ notifications:
6
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in single_xlsx.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Masato Ikeda
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,77 @@
1
+ [![Build Status](https://travis-ci.org/a2ikm/single_xlsx.svg)](https://travis-ci.org/a2ikm/single_xlsx)
2
+
3
+ # SingleXLSX
4
+
5
+ SingleXLSX wraps [rubyXL](http://rubygems.org/gems/rubyXL) to read and write single-sheet XLSX files like ruby's standard CSV library.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'single_xlsx'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install single_xlsx
22
+
23
+ ## Usage
24
+
25
+ ### Read
26
+
27
+ You can read XLSX files into `Array` of `Array`.
28
+
29
+ | Name | Age |
30
+ |----------|-----|
31
+ | Einstein | 76 |
32
+ | Feynman | 69 |
33
+
34
+ ```ruby
35
+ require "single_xlsx"
36
+
37
+ SingleXLSX.read("path/to/xlsx")
38
+ #=> [
39
+ ["Name", "Age"],
40
+ ["Einstein", 76],
41
+ ["Feynman", 69]
42
+ ]
43
+ ```
44
+
45
+ ### Write
46
+
47
+ You can write XLSX data into `String`.
48
+
49
+ ```ruby
50
+ require "single_xlsx"
51
+
52
+ binary = SingleXLSX.generate do |sheet|
53
+ sheet << ["Name", "Age"]
54
+ sheet << ["Einstein", 76]
55
+ sheet << ["Feynman", 69]
56
+ end
57
+ ```
58
+
59
+ or into a file.
60
+
61
+ ```ruby
62
+ require "single_xlsx"
63
+
64
+ SingleXLSX.open("path/to/xlsx") do |sheet|
65
+ sheet << ["Name", "Age"]
66
+ sheet << ["Einstein", 76]
67
+ sheet << ["Feynman", 69]
68
+ end
69
+ ```
70
+
71
+ ## Contributing
72
+
73
+ 1. Fork it ( https://github.com/a2ikm/single_xlsx/fork )
74
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
75
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
76
+ 4. Push to the branch (`git push origin my-new-feature`)
77
+ 5. Create a new Pull Request
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rake/testtask"
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'lib'
6
+ t.libs << 'test'
7
+ t.pattern = 'test/**/*_test.rb'
8
+ t.verbose = false
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,4 @@
1
+ require "rubyXL"
2
+ require "single_xlsx/version"
3
+ require "single_xlsx/reading"
4
+ require "single_xlsx/writing"
@@ -0,0 +1,15 @@
1
+ require "active_support/core_ext/object/try"
2
+ require "active_support/core_ext/object/blank"
3
+
4
+ module SingleXLSX
5
+ module Reading
6
+ def read(path)
7
+ book = RubyXL::Parser.parse(path)
8
+ book[0].sheet_data.rows.map do |row|
9
+ row.cells.map { |cell| cell.try(:value).presence }
10
+ end
11
+ end
12
+ end
13
+
14
+ extend Reading
15
+ end
@@ -0,0 +1,17 @@
1
+ module SingleXLSX
2
+ class Sheet
3
+ attr_reader :rubyxl_worksheet
4
+
5
+ def initialize(rubyxl_worksheet)
6
+ @rubyxl_worksheet = rubyxl_worksheet
7
+ end
8
+
9
+ def <<(cells)
10
+ row = rubyxl_worksheet.sheet_data.rows.count
11
+ cells.each_with_index do |value, column|
12
+ rubyxl_worksheet.add_cell(row, column, value.presence)
13
+ end
14
+ cells
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module SingleXLSX
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ require "single_xlsx/sheet"
2
+
3
+ module SingleXLSX
4
+ module Writing
5
+ def generate(&block)
6
+ create_book(&block).stream.read
7
+ end
8
+
9
+ def open(path, &block)
10
+ create_book(&block).write(path)
11
+ end
12
+
13
+ private
14
+
15
+ def create_book(&block)
16
+ raise ArgumentError, "no block given" if block.nil?
17
+
18
+ book = RubyXL::Workbook.new
19
+ sheet = Sheet.new(book[0])
20
+ block.call(sheet)
21
+ book
22
+ end
23
+ end
24
+
25
+ extend Writing
26
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'single_xlsx/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "single_xlsx"
8
+ spec.version = SingleXLSX::VERSION
9
+ spec.authors = ["Masato Ikeda"]
10
+ spec.email = ["masato.ikeda@gmail.com"]
11
+ spec.summary = %q{rubyXL wrapper to treat single-sheet XLSX files like CSV.}
12
+ spec.description = %q{rubyXL wrapper to treat single-sheet XLSX files like CSV.}
13
+ spec.homepage = "https://github.com/a2ikm/single_xlsx"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+
22
+ spec.add_dependency "rubyXL", "~> 3.2.6"
23
+ spec.add_dependency "activesupport", ">= 3.2.0"
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+ spec.add_development_dependency "minitest-reporters"
28
+ end
Binary file
@@ -0,0 +1,43 @@
1
+ require "test_helper"
2
+ require "tempfile"
3
+
4
+ class SingleXlsxTest < Minitest::Test
5
+ def test_read_xlsx
6
+ actual = SingleXLSX.read(fixture_path("book1.xlsx"))
7
+ expected = [
8
+ ["Name", "Age"],
9
+ ["Einstein", 76],
10
+ ["Feynman", 69],
11
+ ]
12
+ assert_equal expected, actual
13
+ end
14
+
15
+ # This test is not good test, but it's hard to compare XLSX files directly
16
+ def test_generate_with_block
17
+ actual = SingleXLSX.generate do |sheet|
18
+ sheet << ["Name", "Age"]
19
+ sheet << ["Einstein", 76]
20
+ sheet << ["Feynman", 69]
21
+ end
22
+
23
+ tempfile = Tempfile.new(self.class.name)
24
+ tempfile.write actual
25
+ tempfile.close
26
+ arr_of_arr = SingleXLSX.read(tempfile.path)
27
+
28
+ expected = [
29
+ ["Name", "Age"],
30
+ ["Einstein", 76],
31
+ ["Feynman", 69],
32
+ ]
33
+ assert_equal expected, arr_of_arr
34
+ ensure
35
+ tempfile.unlink if tempfile
36
+ end
37
+
38
+ def test_generate_without_block
39
+ assert_raises ArgumentError do
40
+ SingleXLSX.generate
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,9 @@
1
+ module Helper
2
+ FIXTURES_DIR = File.expand_path("../../fixtures", __FILE__)
3
+
4
+ def fixture_path(relative_path)
5
+ File.join(FIXTURES_DIR, relative_path)
6
+ end
7
+ end
8
+
9
+ Minitest::Test.send :include, Helper
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
2
+ $LOAD_PATH.unshift(File.expand_path("..", __FILE__))
3
+
4
+ require "minitest/autorun"
5
+ require "minitest/reporters"
6
+
7
+ Minitest::Reporters.use! [Minitest::Reporters::ProgressReporter.new]
8
+
9
+ Dir[File.expand_path("../support/*.rb", __FILE__)].each { |file| require file }
10
+
11
+ require "single_xlsx"
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: single_xlsx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masato Ikeda
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubyXL
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-reporters
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: rubyXL wrapper to treat single-sheet XLSX files like CSV.
98
+ email:
99
+ - masato.ikeda@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - lib/single_xlsx.rb
111
+ - lib/single_xlsx/reading.rb
112
+ - lib/single_xlsx/sheet.rb
113
+ - lib/single_xlsx/version.rb
114
+ - lib/single_xlsx/writing.rb
115
+ - single_xlsx.gemspec
116
+ - test/fixtures/book1.xlsx
117
+ - test/single_xlsx_test.rb
118
+ - test/support/helper.rb
119
+ - test/test_helper.rb
120
+ homepage: https://github.com/a2ikm/single_xlsx
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.2.2
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: rubyXL wrapper to treat single-sheet XLSX files like CSV.
144
+ test_files:
145
+ - test/fixtures/book1.xlsx
146
+ - test/single_xlsx_test.rb
147
+ - test/support/helper.rb
148
+ - test/test_helper.rb
149
+ has_rdoc: