dumpster 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +35 -0
- data/Rakefile +7 -0
- data/dumpster.gemspec +22 -0
- data/lib/dumpster.rb +23 -0
- data/lib/dumpster/csv.rb +40 -0
- data/lib/dumpster/excel.rb +25 -0
- data/lib/dumpster/model/generic.rb +15 -0
- data/lib/dumpster/model/sql.rb +16 -0
- data/lib/dumpster/version.rb +3 -0
- data/spec/integration/csv/writer_spec.rb +42 -0
- data/spec/integration/excel/writer_spec.rb +17 -0
- data/spec/integration/spec_helper.rb +6 -0
- data/spec/unit/exporter_spec.rb +27 -0
- data/spec/unit/model/generic_spec.rb +19 -0
- data/spec/unit/spec_helper.rb +5 -0
- data/tasks/spec.rake +13 -0
- metadata +118 -0
data/.gitignore
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
spec/integration/csv/output/
|
19
|
+
spec/integration/excel/output/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Yves Senn
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Dumpster
|
2
|
+
|
3
|
+
Abstraktion für den Export von Daten in Tabellenform. Momentan werden die Formate
|
4
|
+
CSV und XLSX unterstützt.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'dumpster'
|
11
|
+
|
12
|
+
Or install it yourself as:
|
13
|
+
|
14
|
+
$ gem install dumpster
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
data = [['col1-row1', 'col2-row1'], ['col1-row2', 'col2-row2']]
|
20
|
+
model = Dumpster::Model::Generic.new(data)
|
21
|
+
|
22
|
+
writer = Dumpster.csv_writer(model)
|
23
|
+
writer = Dumpster.csv_writer(model, :type => :windows)
|
24
|
+
writer = Dumpster.excel_writer(model)
|
25
|
+
|
26
|
+
writer.write_to_file('/some/directory/some.file')
|
27
|
+
```
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/dumpster.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/dumpster/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Yves Senn"]
|
6
|
+
gem.email = ["yves.senn@garaio.com"]
|
7
|
+
gem.description = %q{Abstraktions-Layer für Exporte im Tabellenformat}
|
8
|
+
gem.summary = %q{Dumpster kann aufbereitete Daten in verschiedenen Formaten ausgeben}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "dumpster"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Dumpster::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency "rake"
|
19
|
+
gem.add_development_dependency "rspec"
|
20
|
+
|
21
|
+
gem.add_development_dependency "axlsx"
|
22
|
+
end
|
data/lib/dumpster.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "dumpster/version"
|
2
|
+
|
3
|
+
require 'dumpster/model/generic'
|
4
|
+
require 'dumpster/model/sql'
|
5
|
+
|
6
|
+
module Dumpster
|
7
|
+
|
8
|
+
def self.csv_writer(model, options = {})
|
9
|
+
require 'dumpster/csv'
|
10
|
+
writer_class = if options[:type] == :windows
|
11
|
+
Dumpster::CSV::WindowsWriter
|
12
|
+
else
|
13
|
+
Dumpster::CSV::Writer
|
14
|
+
end
|
15
|
+
writer_class.new(model)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.excel_writer(model)
|
19
|
+
require 'dumpster/excel'
|
20
|
+
Dumpster::Excel::Writer.new(model)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/dumpster/csv.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module Dumpster
|
4
|
+
module CSV
|
5
|
+
|
6
|
+
class Writer
|
7
|
+
def initialize(model)
|
8
|
+
@model = model
|
9
|
+
end
|
10
|
+
|
11
|
+
def write_to_file(path)
|
12
|
+
File.open(path, 'w+') do |file|
|
13
|
+
write_to file
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def write_to(io)
|
18
|
+
csv = build_csv(io)
|
19
|
+
@model.each do |row|
|
20
|
+
csv << row
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def build_csv(io)
|
25
|
+
::CSV.new(io, csv_options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def csv_options
|
29
|
+
{}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class WindowsWriter < Writer
|
34
|
+
def csv_options
|
35
|
+
{:col_sep => ';'}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'axlsx'
|
2
|
+
|
3
|
+
module Dumpster
|
4
|
+
module Excel
|
5
|
+
class Writer
|
6
|
+
|
7
|
+
def initialize(model)
|
8
|
+
@model = model
|
9
|
+
end
|
10
|
+
|
11
|
+
def write_to_file(path)
|
12
|
+
package = Axlsx::Package.new
|
13
|
+
workbook = package.workbook
|
14
|
+
workbook.add_worksheet(:name => "Worksheet 1") do |sheet|
|
15
|
+
@model.each do |row|
|
16
|
+
sheet.add_row(row)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
package.serialize(path)
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'integration/spec_helper'
|
2
|
+
|
3
|
+
describe Dumpster::CSV::Writer do
|
4
|
+
|
5
|
+
let(:data) { [['col1-row1', 'col2-row1'], ['col1-row2', 'col2-row2']] }
|
6
|
+
let(:model) { Dumpster::Model::Generic.new(data) }
|
7
|
+
subject { Dumpster::CSV::Writer.new(model) }
|
8
|
+
|
9
|
+
it '#write_to schreibt die CSV Daten auf ein IO Objekt' do
|
10
|
+
io = StringIO.new
|
11
|
+
subject.write_to(io)
|
12
|
+
|
13
|
+
io.rewind
|
14
|
+
io.readlines.should == ["col1-row1,col2-row1\n", "col1-row2,col2-row2\n"]
|
15
|
+
end
|
16
|
+
|
17
|
+
it '#write_to_file schreibt die CSV Daten in eine Datei' do
|
18
|
+
output_path = File.join(File.dirname(__FILE__), 'output', 'example.csv')
|
19
|
+
|
20
|
+
FileUtils.rm_f(output_path)
|
21
|
+
subject.write_to_file(output_path)
|
22
|
+
|
23
|
+
File.readlines(output_path).should == ["col1-row1,col2-row1\n", "col1-row2,col2-row2\n"]
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe Dumpster::CSV::WindowsWriter do
|
29
|
+
|
30
|
+
let(:data) { [['col1-row1', 'col2-row1'], ['col1-row2', 'col2-row2']] }
|
31
|
+
let(:model) { Dumpster::Model::Generic.new(data) }
|
32
|
+
subject { Dumpster::CSV::WindowsWriter.new(model) }
|
33
|
+
|
34
|
+
it '#write_to schreibt die CSV Daten auf ein IO Objekt' do
|
35
|
+
io = StringIO.new
|
36
|
+
subject.write_to(io)
|
37
|
+
|
38
|
+
io.rewind
|
39
|
+
io.readlines.should == ["col1-row1;col2-row1\n", "col1-row2;col2-row2\n"]
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'integration/spec_helper'
|
2
|
+
|
3
|
+
describe Dumpster::Excel::Writer do
|
4
|
+
|
5
|
+
let(:data) { [['col1-row1', 'col2-row1'], ['col1-row2', 'col2-row2']] }
|
6
|
+
let(:model) { Dumpster::Model::Generic.new(data) }
|
7
|
+
subject { described_class.new(model) }
|
8
|
+
|
9
|
+
it '#write_to_file schreibt die CSV Daten in eine Datei' do
|
10
|
+
output_path = File.join(File.dirname(__FILE__), 'output', 'example.xlsx')
|
11
|
+
FileUtils.rm_f(output_path)
|
12
|
+
|
13
|
+
subject.write_to_file(output_path)
|
14
|
+
|
15
|
+
File.exists?(output_path).should be_true
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'dumpster'
|
3
|
+
|
4
|
+
describe Dumpster do
|
5
|
+
|
6
|
+
let(:model) { stub }
|
7
|
+
|
8
|
+
context 'CSV' do
|
9
|
+
it '#csv_writer erstellt einen CSV-Writer für das Model' do
|
10
|
+
writer = described_class.csv_writer(model)
|
11
|
+
writer.should be_kind_of(Dumpster::CSV::Writer)
|
12
|
+
end
|
13
|
+
|
14
|
+
it '#csv_writer kann einen Windows-spezifischen Writer erstellen' do
|
15
|
+
writer = described_class.csv_writer(model, :type => :windows)
|
16
|
+
writer.should be_kind_of(Dumpster::CSV::WindowsWriter)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'Excel' do
|
21
|
+
it '#excel_writer erstellt einen Excel-Writer für das Model' do
|
22
|
+
writer = described_class.excel_writer(model)
|
23
|
+
writer.should be_kind_of(Dumpster::Excel::Writer)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'unit/spec_helper'
|
3
|
+
|
4
|
+
require 'dumpster/model/generic'
|
5
|
+
|
6
|
+
describe Dumpster::Model::Generic do
|
7
|
+
|
8
|
+
let(:data) { [['col1-row1', 'col2-row1'], ['col1-row2', 'col2-row2']] }
|
9
|
+
subject { described_class.new(data) }
|
10
|
+
|
11
|
+
it '#each iteriert über die Daten' do
|
12
|
+
rows = []
|
13
|
+
subject.each do |row|
|
14
|
+
rows << row
|
15
|
+
end
|
16
|
+
rows.should == data
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/tasks/spec.rake
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
|
3
|
+
namespace :spec do
|
4
|
+
RSpec::Core::RakeTask.new(:unit) do |t|
|
5
|
+
t.pattern = "spec/unit/**/*_spec.rb"
|
6
|
+
end
|
7
|
+
|
8
|
+
RSpec::Core::RakeTask.new(:integration) do |t|
|
9
|
+
t.pattern = "spec/integration/**/*_spec.rb"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
task :spec => ['spec:unit', 'spec:integration']
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dumpster
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Yves Senn
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: axlsx
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Abstraktions-Layer für Exporte im Tabellenformat
|
63
|
+
email:
|
64
|
+
- yves.senn@garaio.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- dumpster.gemspec
|
75
|
+
- lib/dumpster.rb
|
76
|
+
- lib/dumpster/csv.rb
|
77
|
+
- lib/dumpster/excel.rb
|
78
|
+
- lib/dumpster/model/generic.rb
|
79
|
+
- lib/dumpster/model/sql.rb
|
80
|
+
- lib/dumpster/version.rb
|
81
|
+
- spec/integration/csv/writer_spec.rb
|
82
|
+
- spec/integration/excel/writer_spec.rb
|
83
|
+
- spec/integration/spec_helper.rb
|
84
|
+
- spec/unit/exporter_spec.rb
|
85
|
+
- spec/unit/model/generic_spec.rb
|
86
|
+
- spec/unit/spec_helper.rb
|
87
|
+
- tasks/spec.rake
|
88
|
+
homepage: ''
|
89
|
+
licenses: []
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.8.21
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: Dumpster kann aufbereitete Daten in verschiedenen Formaten ausgeben
|
112
|
+
test_files:
|
113
|
+
- spec/integration/csv/writer_spec.rb
|
114
|
+
- spec/integration/excel/writer_spec.rb
|
115
|
+
- spec/integration/spec_helper.rb
|
116
|
+
- spec/unit/exporter_spec.rb
|
117
|
+
- spec/unit/model/generic_spec.rb
|
118
|
+
- spec/unit/spec_helper.rb
|