spreadsheet_fuel 0.1.0.pre.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +8 -0
- data/.gitignore +6 -0
- data/.rubocop.yml +36 -0
- data/.ruby-version +1 -0
- data/.travis.yml +24 -0
- data/CHANGELOG.md +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/Guardfile +16 -0
- data/LICENSE +7 -0
- data/README.md +163 -0
- data/Rakefile +17 -0
- data/bin/console +18 -0
- data/exe/.gitkeep +0 -0
- data/lib/spreadsheet_fuel.rb +18 -0
- data/lib/spreadsheet_fuel/library.rb +19 -0
- data/lib/spreadsheet_fuel/library/deserialize/xlsx.rb +66 -0
- data/lib/spreadsheet_fuel/library/serialize/xlsx.rb +72 -0
- data/lib/spreadsheet_fuel/modeling.rb +10 -0
- data/lib/spreadsheet_fuel/modeling/sheet_mapping.rb +27 -0
- data/lib/spreadsheet_fuel/version.rb +12 -0
- data/spreadsheet_fuel.gemspec +43 -0
- metadata +225 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e0d7b1daedd134e842cc1c82b342c117ba907277fdeea556d20b79911587cfb7
|
4
|
+
data.tar.gz: 901d128532d5e0debc7a5317630f3e19da9092f18cf5cf8870fb1c3419031a0d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cbd0ce3f93e743d4ef1081e9719fad231f025d6a63a9bf81e0accf4bb70509d8811ef3361a8907003840e9c1878a6be8c6f277e4943f2c74a2a6b9068ed1f12e
|
7
|
+
data.tar.gz: 533b1cb9c8632ee93277f344c0093869eadba71a3a53c7ff16ff7296c2a77e84e2d360e609b3ddbac68f6dba46587d4adf71d8dd2362e61f59d04ef8b1e7a58b
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5
|
3
|
+
NewCops: enable
|
4
|
+
|
5
|
+
Layout/LineLength:
|
6
|
+
Max: 100
|
7
|
+
Exclude:
|
8
|
+
- spreadsheet_fuel.gemspec
|
9
|
+
|
10
|
+
Metrics/BlockLength:
|
11
|
+
ExcludedMethods:
|
12
|
+
- let
|
13
|
+
- it
|
14
|
+
- describe
|
15
|
+
- context
|
16
|
+
- specify
|
17
|
+
- define
|
18
|
+
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Max: 30
|
21
|
+
|
22
|
+
Metrics/AbcSize:
|
23
|
+
Max: 25
|
24
|
+
|
25
|
+
Metrics/ClassLength:
|
26
|
+
Max: 125
|
27
|
+
|
28
|
+
Metrics/ParameterLists:
|
29
|
+
CountKeywordArgs: false
|
30
|
+
|
31
|
+
Style/TrailingCommaInHashLiteral:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Style/TrailingCommaInArrayLiteral:
|
35
|
+
Enabled: false
|
36
|
+
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.6
|
data/.travis.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
env:
|
2
|
+
global:
|
3
|
+
- CC_TEST_REPORTER_ID=2d57d597269e2cb04a63d0a7262927cf811abb7ab528da7de681943b212b4134
|
4
|
+
language: ruby
|
5
|
+
rvm:
|
6
|
+
# Build on the latest stable of all supported Rubies (https://www.ruby-lang.org/en/downloads/):
|
7
|
+
- 2.5.8
|
8
|
+
- 2.6.6
|
9
|
+
- 2.7.1
|
10
|
+
cache: bundler
|
11
|
+
before_script:
|
12
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
13
|
+
- chmod +x ./cc-test-reporter
|
14
|
+
- ./cc-test-reporter before-build
|
15
|
+
script:
|
16
|
+
- bundle exec rubocop
|
17
|
+
- bundle exec rspec spec --format documentation
|
18
|
+
after_script:
|
19
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
20
|
+
addons:
|
21
|
+
# https://docs.travis-ci.com/user/uploading-artifacts/
|
22
|
+
artifacts:
|
23
|
+
paths:
|
24
|
+
- Gemfile.lock
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at oss@bluemarblepayroll.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
guard :rspec, cmd: 'DISABLE_SIMPLECOV=true bundle exec rspec --format=documentation' do
|
4
|
+
require 'guard/rspec/dsl'
|
5
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
6
|
+
|
7
|
+
# RSpec files
|
8
|
+
rspec = dsl.rspec
|
9
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
10
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
11
|
+
watch(rspec.spec_files)
|
12
|
+
|
13
|
+
# Ruby files
|
14
|
+
ruby = dsl.ruby
|
15
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
16
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright 2020 Blue Marble Payroll, LLC
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
# Spreadsheet Fuel
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/spreadsheet_fuel.svg)](https://badge.fury.io/rb/spreadsheet_fuel) [![Build Status](https://travis-ci.com/bluemarblepayroll/spreadsheet_fuel.svg?branch=master)](https://travis-ci.com/bluemarblepayroll/spreadsheet_fuel) [![Maintainability](https://api.codeclimate.com/v1/badges/b03892fff9af19eaa7ee/maintainability)](https://codeclimate.com/github/bluemarblepayroll/spreadsheet_fuel/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/b03892fff9af19eaa7ee/test_coverage)](https://codeclimate.com/github/bluemarblepayroll/spreadsheet_fuel/test_coverage) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
4
|
+
|
5
|
+
This library is a plugin for [Burner](https://github.com/bluemarblepayroll/burner). It adds jobs focused around spreadsheet processing such as reading and writing Microsoft Excel Open XML spreadsheets (.xlsx files).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
To install through Rubygems:
|
10
|
+
|
11
|
+
````bash
|
12
|
+
gem install spreadsheet_fuel
|
13
|
+
````
|
14
|
+
|
15
|
+
You can also add this to your Gemfile:
|
16
|
+
|
17
|
+
````bash
|
18
|
+
bundle add spreadsheet_fuel
|
19
|
+
````
|
20
|
+
## Jobs
|
21
|
+
|
22
|
+
Refer to the [Burner](https://github.com/bluemarblepayroll/burner) library for more specific information on how Burner works. This section will just focus on what this library directly adds.
|
23
|
+
|
24
|
+
* **spreadsheet_fuel/deserialize/xlsx** [register, sheet_mappings]: Take the register, parse it as a Microsoft Excel Open XML spreadsheet and store the sheet data in the specified sheet_mappings' registers. Each sheet mapping specifies which sheet to read and where to place the parsed data. If no sheet mappings are specified then the default sheet will be parsed and placed in the register.
|
25
|
+
* **spreadsheet_fuel/serialize/xlsx** [register, sheet_mappings]: Create a Microsoft Excel Open XML workbook and write all specified register data into their respective sheets. The sheet_mappings will specify which sheets get data and from which register.
|
26
|
+
|
27
|
+
## Examples
|
28
|
+
|
29
|
+
### Reading an Excel Spreadsheet
|
30
|
+
|
31
|
+
Let's use the example fixture file as an example XLSX file to read and parse (located at `spec/fixtures/patients_and_notes.xlsx`). We could execute the following Burner pipeline:
|
32
|
+
|
33
|
+
````ruby
|
34
|
+
pipeline = {
|
35
|
+
jobs: [
|
36
|
+
{
|
37
|
+
name: 'read',
|
38
|
+
type: 'b/io/read',
|
39
|
+
path: File.join('spec', 'fixtures', 'patients_and_notes.xlsx') # change as necessary
|
40
|
+
},
|
41
|
+
{
|
42
|
+
name: 'parse',
|
43
|
+
type: 'spreadsheet_fuel/deserialize/xlsx',
|
44
|
+
sheet_mappings: [
|
45
|
+
{ sheet: 'Patients', register: 'patients' },
|
46
|
+
{ sheet: 'Notes', register: 'notes' }
|
47
|
+
]
|
48
|
+
},
|
49
|
+
],
|
50
|
+
steps: %w[read parse]
|
51
|
+
}
|
52
|
+
|
53
|
+
payload = Burner::Payload.new
|
54
|
+
|
55
|
+
Burner::Pipeline.make(pipeline).execute(payload: payload)
|
56
|
+
````
|
57
|
+
|
58
|
+
Inspecting the payload's registers would now look something like this:
|
59
|
+
|
60
|
+
````ruby
|
61
|
+
patients = payload[:patients] # [%w[chart_number first_name last_name], ...]
|
62
|
+
notes = payload[:notes] # [%w[emp_number note_number contents],, ...]
|
63
|
+
````
|
64
|
+
|
65
|
+
### Writing an Excel Spreadsheet
|
66
|
+
|
67
|
+
Let's do an exact opposite of the above example. Let's say we would like to write a spreadsheet given a few registers of data:
|
68
|
+
|
69
|
+
````ruby
|
70
|
+
pipeline = {
|
71
|
+
jobs: [
|
72
|
+
{
|
73
|
+
name: 'load_patients',
|
74
|
+
type: 'b/value/static',
|
75
|
+
register: :patients,
|
76
|
+
value: [
|
77
|
+
%w[chart_number first_name last_name],
|
78
|
+
[123, 'Bozo', 'Clown'],
|
79
|
+
['A456', nil, 'Rizzo'],
|
80
|
+
%w[Z789 Hops Bunny]
|
81
|
+
]
|
82
|
+
},
|
83
|
+
{
|
84
|
+
name: 'load_notes',
|
85
|
+
type: 'b/value/static',
|
86
|
+
register: :notes,
|
87
|
+
value: [
|
88
|
+
%w[emp_number note_number contents],
|
89
|
+
['A456', 1, 'Hello world!'],
|
90
|
+
[nil, 2, 'Hello, again!'],
|
91
|
+
['Z789', 1, 'Something something…']
|
92
|
+
]
|
93
|
+
},
|
94
|
+
{
|
95
|
+
name: 'write_workbook',
|
96
|
+
type: 'spreadsheet_fuel/serialize/xlsx',
|
97
|
+
register: :spreadsheet,
|
98
|
+
sheet_mappings: [
|
99
|
+
{ sheet: 'Patients', register: :patients },
|
100
|
+
{ sheet: 'Notes', register: :notes }
|
101
|
+
]
|
102
|
+
},
|
103
|
+
],
|
104
|
+
steps: %w[load_patients load_notes write_workbook]
|
105
|
+
}
|
106
|
+
|
107
|
+
payload = Burner::Payload.new
|
108
|
+
|
109
|
+
Burner::Pipeline.make(pipeline).execute(payload: payload)
|
110
|
+
````
|
111
|
+
|
112
|
+
## Contributing
|
113
|
+
|
114
|
+
### Development Environment Configuration
|
115
|
+
|
116
|
+
Basic steps to take to get this repository compiling:
|
117
|
+
|
118
|
+
1. Install [Ruby](https://www.ruby-lang.org/en/documentation/installation/) (check spreadsheet_fuel.gemspec for versions supported)
|
119
|
+
2. Install bundler (gem install bundler)
|
120
|
+
3. Clone the repository (git clone git@github.com:bluemarblepayroll/spreadsheet_fuel.git)
|
121
|
+
4. Navigate to the root folder (cd spreadsheet_fuel)
|
122
|
+
5. Install dependencies (bundle)
|
123
|
+
|
124
|
+
### Running Tests
|
125
|
+
|
126
|
+
To execute the test suite run:
|
127
|
+
|
128
|
+
````bash
|
129
|
+
bundle exec rspec spec --format documentation
|
130
|
+
````
|
131
|
+
|
132
|
+
Alternatively, you can have Guard watch for changes:
|
133
|
+
|
134
|
+
````bash
|
135
|
+
bundle exec guard
|
136
|
+
````
|
137
|
+
|
138
|
+
Also, do not forget to run Rubocop:
|
139
|
+
|
140
|
+
````bash
|
141
|
+
bundle exec rubocop
|
142
|
+
````
|
143
|
+
|
144
|
+
### Publishing
|
145
|
+
|
146
|
+
Note: ensure you have proper authorization before trying to publish new versions.
|
147
|
+
|
148
|
+
After code changes have successfully gone through the Pull Request review process then the following steps should be followed for publishing new versions:
|
149
|
+
|
150
|
+
1. Merge Pull Request into master
|
151
|
+
2. Update `lib/spreadsheet_fuel/version.rb` using [semantic versioning](https://semver.org/)
|
152
|
+
3. Install dependencies: `bundle`
|
153
|
+
4. Update `CHANGELOG.md` with release notes
|
154
|
+
5. Commit & push master to remote and ensure CI builds master successfully
|
155
|
+
6. Run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
156
|
+
|
157
|
+
## Code of Conduct
|
158
|
+
|
159
|
+
Everyone interacting in this codebase, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/bluemarblepayroll/spreadsheet_fuel/blob/master/CODE_OF_CONDUCT.md).
|
160
|
+
|
161
|
+
## License
|
162
|
+
|
163
|
+
This project is MIT Licensed.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2020-present, Blue Marble Payroll, LLC
|
5
|
+
#
|
6
|
+
# This source code is licensed under the MIT license found in the
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'bundler/gem_tasks'
|
11
|
+
require 'rspec/core/rake_task'
|
12
|
+
require 'rubocop/rake_task'
|
13
|
+
|
14
|
+
RSpec::Core::RakeTask.new(:spec)
|
15
|
+
RuboCop::RakeTask.new
|
16
|
+
|
17
|
+
task default: %i[rubocop spec]
|
data/bin/console
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# Copyright (c) 2020-present, Blue Marble Payroll, LLC
|
6
|
+
#
|
7
|
+
# This source code is licensed under the MIT license found in the
|
8
|
+
# LICENSE file in the root directory of this source tree.
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'bundler/setup'
|
12
|
+
require 'spreadsheet_fuel'
|
13
|
+
|
14
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
15
|
+
# with your gem easier. You can also use a different console, if you like.
|
16
|
+
|
17
|
+
require 'pry'
|
18
|
+
Pry.start
|
data/exe/.gitkeep
ADDED
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2020-present, Blue Marble Payroll, LLC
|
5
|
+
#
|
6
|
+
# This source code is licensed under the MIT license found in the
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'acts_as_hashable'
|
11
|
+
require 'burner'
|
12
|
+
require 'fast_excel'
|
13
|
+
require 'roo'
|
14
|
+
|
15
|
+
# Require modeling first, which can be used across any job classes.
|
16
|
+
require_relative 'spreadsheet_fuel/modeling'
|
17
|
+
|
18
|
+
require_relative 'spreadsheet_fuel/library'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2020-present, Blue Marble Payroll, LLC
|
5
|
+
#
|
6
|
+
# This source code is licensed under the MIT license found in the
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
8
|
+
#
|
9
|
+
|
10
|
+
require_relative 'library/deserialize/xlsx'
|
11
|
+
require_relative 'library/serialize/xlsx'
|
12
|
+
|
13
|
+
module Burner
|
14
|
+
# Open up the Burner::Jobs class and register our jobs.
|
15
|
+
class Jobs
|
16
|
+
register 'spreadsheet_fuel/deserialize/xlsx', SpreadsheetFuel::Library::Deserialize::Xlsx
|
17
|
+
register 'spreadsheet_fuel/serialize/xlsx', SpreadsheetFuel::Library::Serialize::Xlsx
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2020-present, Blue Marble Payroll, LLC
|
5
|
+
#
|
6
|
+
# This source code is licensed under the MIT license found in the
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
8
|
+
#
|
9
|
+
|
10
|
+
module SpreadsheetFuel
|
11
|
+
module Library
|
12
|
+
module Deserialize
|
13
|
+
# Read in the input register and parse it as a Microsoft Excel Open XML Spreadsheet.
|
14
|
+
# Sheets can be specified and mapped to registers using the sheet_mappings option.
|
15
|
+
# If not sheet_mappings exist, then the default functionality will be to parse the
|
16
|
+
# default sheet and overwrite the input register with the sheet's parsed contents.
|
17
|
+
# The parsed content for each sheet will be a two-dimensional array.
|
18
|
+
#
|
19
|
+
# Expected Payload[register] input: XLSX blob of data.
|
20
|
+
# Payload[register|sheet_mappings.register] output: array of arrays.
|
21
|
+
class Xlsx < Burner::JobWithRegister
|
22
|
+
attr_reader :sheet_mappings
|
23
|
+
|
24
|
+
def initialize(name:, register: Burner::DEFAULT_REGISTER, sheet_mappings: nil)
|
25
|
+
super(name: name, register: register)
|
26
|
+
|
27
|
+
@sheet_mappings = Modeling::SheetMapping.array(sheet_mappings)
|
28
|
+
|
29
|
+
# If no sheets/register mappings are specified then lets just use the default
|
30
|
+
# sheet and the current register.
|
31
|
+
if @sheet_mappings.empty?
|
32
|
+
@sheet_mappings << Modeling::SheetMapping.new(register: register)
|
33
|
+
end
|
34
|
+
|
35
|
+
freeze
|
36
|
+
end
|
37
|
+
|
38
|
+
def perform(output, payload)
|
39
|
+
output.detail("Reading spreadsheet in register: #{register}")
|
40
|
+
|
41
|
+
value = payload[register]
|
42
|
+
io = StringIO.new(value)
|
43
|
+
book = Roo::Excelx.new(io)
|
44
|
+
|
45
|
+
sheet_mappings.each do |sheet_mapping|
|
46
|
+
rows = sheet_mapping.sheet ? book.sheet(sheet_mapping.sheet).to_a : book.to_a
|
47
|
+
sheet = friendly_sheet(sheet_mapping.sheet)
|
48
|
+
message = <<~MESSAGE
|
49
|
+
Loading #{rows.length} record(s) from #{sheet} into register: #{register}
|
50
|
+
MESSAGE
|
51
|
+
|
52
|
+
output.detail(message)
|
53
|
+
|
54
|
+
payload[sheet_mapping.register] = rows
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def friendly_sheet(name)
|
61
|
+
name ? "sheet: #{name}" : 'the default sheet'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2020-present, Blue Marble Payroll, LLC
|
5
|
+
#
|
6
|
+
# This source code is licensed under the MIT license found in the
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
8
|
+
#
|
9
|
+
|
10
|
+
module SpreadsheetFuel
|
11
|
+
module Library
|
12
|
+
module Serialize
|
13
|
+
# This job can take in one or many registers and create a Microsoft Excel Open XML Spreadsheet
|
14
|
+
# file out of them. Each register will be written to the specified sheets within
|
15
|
+
# the workbook. If no sheet_mappings are entered, then the input register will be used
|
16
|
+
# for input and output and only one sheet will be created with the name 'Sheet1'.
|
17
|
+
#
|
18
|
+
# Expected Payload[register|sheet_mappings.register] input: array of arrays.
|
19
|
+
# Payload[register|sheet_mappings.register] output: XLSX data string blob.
|
20
|
+
class Xlsx < Burner::JobWithRegister
|
21
|
+
DEFAULT_SHEET = 'Sheet1'
|
22
|
+
|
23
|
+
attr_reader :sheet_mappings
|
24
|
+
|
25
|
+
def initialize(name:, register: Burner::DEFAULT_REGISTER, sheet_mappings: nil)
|
26
|
+
super(name: name, register: register)
|
27
|
+
|
28
|
+
@sheet_mappings = Modeling::SheetMapping.array(sheet_mappings)
|
29
|
+
|
30
|
+
# If no sheets/register mappings are specified then lets just use the default
|
31
|
+
# sheet and the current register.
|
32
|
+
if @sheet_mappings.empty?
|
33
|
+
@sheet_mappings << Modeling::SheetMapping.new(register: register, sheet: DEFAULT_SHEET)
|
34
|
+
end
|
35
|
+
|
36
|
+
freeze
|
37
|
+
end
|
38
|
+
|
39
|
+
def perform(output, payload)
|
40
|
+
output.detail("Writing spreadsheet to register: #{register}")
|
41
|
+
|
42
|
+
# This will implicitly create a tempfile for FastExcel to use
|
43
|
+
workbook = FastExcel.open
|
44
|
+
|
45
|
+
sheet_mappings.each do |sheet_mapping|
|
46
|
+
name = sheet_mapping.sheet.to_s
|
47
|
+
worksheet = workbook.add_worksheet(name)
|
48
|
+
rows = array(payload[sheet_mapping.register])
|
49
|
+
|
50
|
+
output.detail("Writing #{rows.length} row(s) to sheet: #{name}")
|
51
|
+
|
52
|
+
rows.each { |row| worksheet.append_row(row) }
|
53
|
+
end
|
54
|
+
|
55
|
+
# readstring should close and remove the tmpfile for us:
|
56
|
+
# https://github.com/Paxa/fast_excel/blob/master/lib/fast_excel.rb#L393
|
57
|
+
value = workbook.read_string
|
58
|
+
|
59
|
+
payload[register] = value
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def add_worksheet(workbook)
|
65
|
+
name = sheet ? sheet.to_s : DEFAULT_SHEET_NAME
|
66
|
+
|
67
|
+
workbook.add_worksheet(name)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2020-present, Blue Marble Payroll, LLC
|
5
|
+
#
|
6
|
+
# This source code is licensed under the MIT license found in the
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
8
|
+
#
|
9
|
+
|
10
|
+
require_relative 'modeling/sheet_mapping'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2020-present, Blue Marble Payroll, LLC
|
5
|
+
#
|
6
|
+
# This source code is licensed under the MIT license found in the
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
8
|
+
#
|
9
|
+
|
10
|
+
module SpreadsheetFuel
|
11
|
+
module Modeling
|
12
|
+
# Connects and maps a sheet name or index to a register name.
|
13
|
+
# This can be used in either direction: sheet to register or register to sheet.
|
14
|
+
class SheetMapping
|
15
|
+
acts_as_hashable
|
16
|
+
|
17
|
+
attr_reader :register, :sheet
|
18
|
+
|
19
|
+
def initialize(register: Burner::DEFAULT_REGISTER, sheet: nil)
|
20
|
+
@register = register.to_s
|
21
|
+
@sheet = sheet
|
22
|
+
|
23
|
+
freeze
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2020-present, Blue Marble Payroll, LLC
|
5
|
+
#
|
6
|
+
# This source code is licensed under the MIT license found in the
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
8
|
+
#
|
9
|
+
|
10
|
+
module SpreadsheetFuel
|
11
|
+
VERSION = '0.1.0-alpha'
|
12
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require './lib/spreadsheet_fuel/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'spreadsheet_fuel'
|
7
|
+
s.version = SpreadsheetFuel::VERSION
|
8
|
+
s.summary = 'Spreadsheet jobs for Burner'
|
9
|
+
|
10
|
+
s.description = <<-DESCRIPTION
|
11
|
+
This library adds spreadsheet-centric jobs to the Burner library. Burner does not ship with non-CSV spreadsheet jobs out of the box.
|
12
|
+
DESCRIPTION
|
13
|
+
|
14
|
+
s.authors = ['Matthew Ruggio']
|
15
|
+
s.email = ['mruggio@bluemarblepayroll.com']
|
16
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
s.bindir = 'exe'
|
18
|
+
s.executables = %w[]
|
19
|
+
s.homepage = 'https://github.com/bluemarblepayroll/spreadsheet_fuel'
|
20
|
+
s.license = 'MIT'
|
21
|
+
s.metadata = {
|
22
|
+
'bug_tracker_uri' => 'https://github.com/bluemarblepayroll/spreadsheet_fuel/issues',
|
23
|
+
'changelog_uri' => 'https://github.com/bluemarblepayroll/spreadsheet_fuel/blob/master/CHANGELOG.md',
|
24
|
+
'documentation_uri' => 'https://www.rubydoc.info/gems/spreadsheet_fuel',
|
25
|
+
'homepage_uri' => s.homepage,
|
26
|
+
'source_code_uri' => s.homepage
|
27
|
+
}
|
28
|
+
|
29
|
+
s.required_ruby_version = '>= 2.5'
|
30
|
+
|
31
|
+
s.add_dependency('acts_as_hashable', '~>1.2')
|
32
|
+
s.add_dependency('burner', '~>1.0')
|
33
|
+
s.add_dependency('fast_excel', '~>0.3')
|
34
|
+
s.add_dependency('roo', '~> 2.8')
|
35
|
+
|
36
|
+
s.add_development_dependency('guard-rspec', '~>4.7')
|
37
|
+
s.add_development_dependency('pry', '~>0')
|
38
|
+
s.add_development_dependency('rake', '~> 13')
|
39
|
+
s.add_development_dependency('rspec', '~> 3.8')
|
40
|
+
s.add_development_dependency('rubocop', '~>0.90.0')
|
41
|
+
s.add_development_dependency('simplecov', '~>0.18.5')
|
42
|
+
s.add_development_dependency('simplecov-console', '~>0.7.0')
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spreadsheet_fuel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.pre.alpha
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Ruggio
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: acts_as_hashable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: burner
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fast_excel
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: roo
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.8'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
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
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '13'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '13'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.8'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.8'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.90.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.90.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.18.5
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.18.5
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: simplecov-console
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.7.0
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.7.0
|
167
|
+
description: " This library adds spreadsheet-centric jobs to the Burner library.
|
168
|
+
\ Burner does not ship with non-CSV spreadsheet jobs out of the box.\n"
|
169
|
+
email:
|
170
|
+
- mruggio@bluemarblepayroll.com
|
171
|
+
executables: []
|
172
|
+
extensions: []
|
173
|
+
extra_rdoc_files: []
|
174
|
+
files:
|
175
|
+
- ".editorconfig"
|
176
|
+
- ".gitignore"
|
177
|
+
- ".rubocop.yml"
|
178
|
+
- ".ruby-version"
|
179
|
+
- ".travis.yml"
|
180
|
+
- CHANGELOG.md
|
181
|
+
- CODE_OF_CONDUCT.md
|
182
|
+
- Gemfile
|
183
|
+
- Guardfile
|
184
|
+
- LICENSE
|
185
|
+
- README.md
|
186
|
+
- Rakefile
|
187
|
+
- bin/console
|
188
|
+
- exe/.gitkeep
|
189
|
+
- lib/spreadsheet_fuel.rb
|
190
|
+
- lib/spreadsheet_fuel/library.rb
|
191
|
+
- lib/spreadsheet_fuel/library/deserialize/xlsx.rb
|
192
|
+
- lib/spreadsheet_fuel/library/serialize/xlsx.rb
|
193
|
+
- lib/spreadsheet_fuel/modeling.rb
|
194
|
+
- lib/spreadsheet_fuel/modeling/sheet_mapping.rb
|
195
|
+
- lib/spreadsheet_fuel/version.rb
|
196
|
+
- spreadsheet_fuel.gemspec
|
197
|
+
homepage: https://github.com/bluemarblepayroll/spreadsheet_fuel
|
198
|
+
licenses:
|
199
|
+
- MIT
|
200
|
+
metadata:
|
201
|
+
bug_tracker_uri: https://github.com/bluemarblepayroll/spreadsheet_fuel/issues
|
202
|
+
changelog_uri: https://github.com/bluemarblepayroll/spreadsheet_fuel/blob/master/CHANGELOG.md
|
203
|
+
documentation_uri: https://www.rubydoc.info/gems/spreadsheet_fuel
|
204
|
+
homepage_uri: https://github.com/bluemarblepayroll/spreadsheet_fuel
|
205
|
+
source_code_uri: https://github.com/bluemarblepayroll/spreadsheet_fuel
|
206
|
+
post_install_message:
|
207
|
+
rdoc_options: []
|
208
|
+
require_paths:
|
209
|
+
- lib
|
210
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
211
|
+
requirements:
|
212
|
+
- - ">="
|
213
|
+
- !ruby/object:Gem::Version
|
214
|
+
version: '2.5'
|
215
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
216
|
+
requirements:
|
217
|
+
- - ">"
|
218
|
+
- !ruby/object:Gem::Version
|
219
|
+
version: 1.3.1
|
220
|
+
requirements: []
|
221
|
+
rubygems_version: 3.0.3
|
222
|
+
signing_key:
|
223
|
+
specification_version: 4
|
224
|
+
summary: Spreadsheet jobs for Burner
|
225
|
+
test_files: []
|