metacrunch-file 1.0.0 → 1.1.0

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
  SHA1:
3
- metadata.gz: 555569202d70aa4a0553d8d3c5ffa7396379e84d
4
- data.tar.gz: f3709c10ca420fed0ab6e3ba9f8b6caf1f2ba6c4
3
+ metadata.gz: f457f5fcca1eb193efe81c0e7c8f02d73b42bc7e
4
+ data.tar.gz: 64f70e6bf5a0d45014853bbae5d09e75456a67c1
5
5
  SHA512:
6
- metadata.gz: e89c3de4bde0f2c03962e44b061aa49069c96c8f7672a2f3954e97e00104977e28699defeb0741986f9379af1b86632b8613b5aad2580ed2e0e9a05e93c058b9
7
- data.tar.gz: c8c17793d191d8aa21e76fc15505e82f3522a2df3009b108d83af8eb10e61112525337bc759a6bfcf3f2c4f3b39c1ac0d8c1e866c90febf32a35b0a3f79e3560
6
+ metadata.gz: 80edcd6aaa76b570371fd14b6bbe59a50df168e2471e265075b5607504ae8270d33a2787dfab48bf038d30d8d8261b1c178d7ec306f127873b2bac1a654f64ac
7
+ data.tar.gz: 3ab68b17ab6f7971e286d6177db0c80a4d1b8a83d1d97b707e1ee188e1af55eb2ba1239bc2d47262abc190f7f52503418577e62e5ec6707f4e5d188b13e77197
@@ -0,0 +1,36 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ - image: circleci/ruby:2.4.1-node-browsers
10
+
11
+ working_directory: ~/repo
12
+
13
+ steps:
14
+ - checkout
15
+
16
+ - run:
17
+ name: Install dependencies
18
+ command: bundle install --jobs=4 --retry=3 --path vendor/bundle
19
+
20
+ - run:
21
+ name: Install CodeClimate test coverage reporter
22
+ command: |
23
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
24
+ chmod +x ./cc-test-reporter
25
+ ./cc-test-reporter before-build
26
+
27
+ - run:
28
+ name: Run tests
29
+ command: |
30
+ mkdir /tmp/test-results
31
+ bundle exec rspec --format progress --format RspecJunitFormatter --out /tmp/test-results/rspec.xml
32
+
33
+ - run:
34
+ name: Upload test coverage report to CodeClimate
35
+ command: ./cc-test-reporter after-build --exit-code $?
36
+
data/Gemfile CHANGED
@@ -5,7 +5,6 @@ gemspec
5
5
  group :development do
6
6
  gem "bundler", ">= 1.15"
7
7
  gem "rake", ">= 12.1"
8
- gem "rspec", ">= 3.5.0", "< 4.0.0"
9
8
 
10
9
  if !ENV["CI"]
11
10
  gem "pry-byebug", ">= 3.5.0"
@@ -13,5 +12,8 @@ group :development do
13
12
  end
14
13
 
15
14
  group :test do
16
- gem "simplecov", ">= 0.15.0"
15
+ gem "rspec", ">= 3.5.0", "< 4.0.0"
16
+ gem "rspec_junit_formatter", ">= 0.3.0"
17
+ gem "simplecov", ">= 0.15.0"
17
18
  end
19
+
data/Readme.md ADDED
@@ -0,0 +1,99 @@
1
+ metacrunch-file
2
+ ===============
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/metacrunch-file.svg)](http://badge.fury.io/rb/metacrunch-file)
5
+ [![Code Climate](https://codeclimate.com/github/ubpb/metacrunch-file/badges/gpa.svg)](https://codeclimate.com/github/ubpb/metacrunch-file)
6
+ [![Test Coverage](https://codeclimate.com/github/ubpb/metacrunch-file/badges/coverage.svg)](https://codeclimate.com/github/ubpb/metacrunch-file/coverage)
7
+ [![CircleCI](https://circleci.com/gh/ubpb/metacrunch-file.svg?style=svg)](https://circleci.com/gh/ubpb/metacrunch-file)
8
+
9
+ This is the official file package for the [metacrunch ETL toolkit](https://github.com/ubpb/metacrunch).
10
+
11
+ Installation
12
+ ------------
13
+
14
+ Include the gem in your `Gemfile`
15
+
16
+ ```ruby
17
+ gem "metacrunch-file", "~> 1.0.0"
18
+ ```
19
+
20
+ and run `$ bundle install` to install it.
21
+
22
+ Or install it manually
23
+
24
+ ```
25
+ $ gem install metacrunch-file
26
+ ```
27
+
28
+
29
+ Usage
30
+ -----
31
+
32
+ *Note: For working examples on how to use this package check out our [demo repository](https://github.com/ubpb/metacrunch-demo).*
33
+
34
+ ### `Metacrunch::File::Source`
35
+
36
+ This class provides a metacrunch `source` implementation that can be used to read data from files in the file system into a metacrunch job. The class can be used to read regular files, compressed files (gzip), tar archives and compressed tar archives (gzip).
37
+
38
+ You can access non-option arguments from the command line using the `ARGV` constant.
39
+
40
+ ```ruby
41
+ # my_job.metacrunch
42
+
43
+ # If you call this example like so
44
+ # $ metacrunch my_job.metacrunch *.xml
45
+ # ARGV will contain all the XML files in the current directory.
46
+ source Metacrunch::File::Source.new(ARGV)
47
+
48
+ # ... or you can set the filenames directly
49
+ source Metacrunch::File::Source.new(["my-data.xml", "my-other-data.xml", "..."])
50
+ ```
51
+
52
+ **Options**
53
+
54
+ NONE.
55
+
56
+ The source yields objects of type `Metacrunch::File::Entry` for every file it reads.
57
+
58
+ ```ruby
59
+ # my_job.metacrunch
60
+
61
+ transformation ->(file_entry) do
62
+ puts "** Got file entry (Metacrunch::File::Entry)"
63
+ puts " Filename: #{file_entry.filename}"
64
+ puts " From archive?: #{file_entry.from_archive?}"
65
+ puts " Name in archive: #{file_entry.archive_filename || '-'}"
66
+ puts " Contents: #{file_entry.contents}"
67
+ end
68
+ ```
69
+
70
+
71
+ ### `Metacrunch::File::XLSXDestination`
72
+
73
+ This class provides a metacrunch `destination` implementation to create simple Excel (xlsx) files.
74
+
75
+ To use this destination a transformation is required to format the data in a proper array that can be feet into the destination. When defining the destination you must provide an array of column names. Each data row passed to the destination must be an array of the same size as the column array.
76
+
77
+ ```ruby
78
+ # my_job.metacrunch
79
+
80
+ transformation ->(data) do
81
+ [data["foo"], data["bar"], ...]
82
+ end
83
+
84
+ source Metacrunch::File::XLSXDestination.new(
85
+ "/tmp/my-data.xlsx", # filename
86
+ ["Column 1", "Column 2", ...], # header columns
87
+ OPTIONS
88
+ )
89
+ ```
90
+
91
+ **Options**
92
+
93
+ * `worksheet_title`: The name of the worksheet. Defaults to `My data`.
94
+
95
+ License
96
+ -------
97
+
98
+ metacrunch-file is available at [github](https://github.com/ubpb/metacrunch-file) under [MIT license](https://github.com/ubpb/metacrunch-file/blob/master/License.txt).
99
+
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Metacrunch
3
3
  module File
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
6
6
  end
@@ -0,0 +1,46 @@
1
+ require "metacrunch/file"
2
+ require "axlsx"
3
+
4
+ module Metacrunch
5
+ class File::XLSXDestination
6
+
7
+ DEFAULT_OPTIONS = {
8
+ worksheet_title: "My data"
9
+ }
10
+
11
+ def initialize(filename, columns, options = {})
12
+ @filename = filename
13
+ @columns = columns
14
+ @options = DEFAULT_OPTIONS.deep_merge(options)
15
+
16
+ @package = Axlsx::Package.new
17
+ @workbook = @package.workbook
18
+ @sheet = @workbook.add_worksheet(name: @options[:worksheet_title])
19
+
20
+ @sheet.add_row(columns, types: :string)
21
+ end
22
+
23
+ def write(row)
24
+ return if row.blank?
25
+ @sheet.add_row(row, types: :string)
26
+ end
27
+
28
+ def close
29
+ # Make the first row a header
30
+ @sheet.sheet_view.pane do |pane|
31
+ pane.top_left_cell = "A2"
32
+ pane.state = :frozen_split
33
+ pane.y_split = 1
34
+ pane.x_split = 0
35
+ pane.active_pane = :bottom_right
36
+ end
37
+
38
+ # Add a filter
39
+ @sheet.auto_filter = @sheet.dimension.sqref
40
+
41
+ # Generate file
42
+ @package.serialize(@filename)
43
+ end
44
+
45
+ end
46
+ end
@@ -5,5 +5,6 @@ module Metacrunch
5
5
  module File
6
6
  require_relative "file/entry"
7
7
  require_relative "file/source"
8
+ require_relative "file/xlsx_destination"
8
9
  end
9
10
  end
@@ -16,4 +16,5 @@ Gem::Specification.new do |spec|
16
16
  spec.require_paths = ["lib"]
17
17
 
18
18
  spec.add_dependency "activesupport", ">= 5.1.0"
19
+ spec.add_dependency "axlsx", "~> 2.0.1"
19
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metacrunch-file
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - René Sprotte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-21 00:00:00.000000000 Z
11
+ date: 2017-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,22 +24,39 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 5.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: axlsx
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.1
27
41
  description:
28
42
  email:
29
43
  executables: []
30
44
  extensions: []
31
45
  extra_rdoc_files: []
32
46
  files:
47
+ - ".circleci/config.yml"
33
48
  - ".gitignore"
34
49
  - ".rspec"
35
50
  - Gemfile
36
51
  - License.txt
37
52
  - Rakefile
53
+ - Readme.md
38
54
  - bin/console
39
55
  - lib/metacrunch/file.rb
40
56
  - lib/metacrunch/file/entry.rb
41
57
  - lib/metacrunch/file/source.rb
42
58
  - lib/metacrunch/file/version.rb
59
+ - lib/metacrunch/file/xlsx_destination.rb
43
60
  - metacrunch-file.gemspec
44
61
  homepage: http://github.com/ubpb/metacrunch-file
45
62
  licenses:
@@ -61,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
78
  version: '0'
62
79
  requirements: []
63
80
  rubyforge_project:
64
- rubygems_version: 2.6.11
81
+ rubygems_version: 2.6.14
65
82
  signing_key:
66
83
  specification_version: 4
67
84
  summary: File package for the metacrunch ETL toolkit.