csv_exporter 0.0.1
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +21 -0
- data/lib/csv_exporter/base.rb +51 -0
- data/lib/csv_exporter/core_ext/active_support.rb +8 -0
- data/lib/csv_exporter/core_ext/array.rb +8 -0
- data/lib/csv_exporter/version.rb +3 -0
- data/lib/csv_exporter.rb +43 -0
- data/lib/tasks/csv_exporter_tasks.rake +4 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 422d00c24e6fffc4522bff8d68c82e9e1373dc07
|
4
|
+
data.tar.gz: 7bffc4ed3ed1eec16f3fb5614938479b50895873
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 05d8d4e87ca205d5c44d744c92146606af32344af676730da036d4068b271bf7f03f8c61c67f1cc711d5a222c0a6edb35285998c5e0cdf55e88f7329a4a7ad86
|
7
|
+
data.tar.gz: 0e13d4a13ddfc235507cb7439bed77c34c5f86cef7f62680aba15512531eb7a1fa8ba6b050bc5c19ebe1b1d1f8a332f362088810f69743645e16c2d73afd98a4
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'CsvExporter'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
require 'active_support/core_ext/hash'
|
3
|
+
|
4
|
+
module CsvExporter
|
5
|
+
class Base
|
6
|
+
|
7
|
+
def csv_file(collection, hash, filename)
|
8
|
+
CSV.open(CsvExporter.file(filename), 'w') do |csv|
|
9
|
+
|
10
|
+
collection.each_with_index do |element, index|
|
11
|
+
# binding.pry if index == 0
|
12
|
+
case element.class.to_s.downcase
|
13
|
+
when 'hash'
|
14
|
+
csv << element.keys if index == 0
|
15
|
+
csv << element.values
|
16
|
+
when 'array'
|
17
|
+
csv << element
|
18
|
+
when 'openstruct'
|
19
|
+
csv << element.to_h.keys.map(&:capitalize) if index == 0
|
20
|
+
csv << element.to_h.values
|
21
|
+
else
|
22
|
+
if hash.is_a?(Hash)
|
23
|
+
hash.symbolize_keys!
|
24
|
+
if hash[:export_fields].present?
|
25
|
+
csv << hash[:export_fields].map(&:capitalize) if index == 0
|
26
|
+
csv << custom_rows(element, hash[:export_fields])
|
27
|
+
else
|
28
|
+
csv << hash.keys.map(&:capitalize) if index == 0
|
29
|
+
csv << custom_rows(element, hash.values)
|
30
|
+
end
|
31
|
+
elsif hash.is_a?(Array)
|
32
|
+
csv << hash.map(&:capitalize) if index == 0
|
33
|
+
csv << custom_rows(element, hash)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def custom_rows(element, hash)
|
45
|
+
hash.map do |v|
|
46
|
+
element.send(v)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
data/lib/csv_exporter.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'csv'
|
3
|
+
require 'csv_exporter/core_ext/array'
|
4
|
+
require 'csv_exporter/base'
|
5
|
+
|
6
|
+
module CsvExporter
|
7
|
+
class RuntimeError < RuntimeError ; end
|
8
|
+
class NotFound < RuntimeError ; end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def load(file, env = nil)
|
13
|
+
@environment = env.to_s if env
|
14
|
+
config = YAML.load_file(file)
|
15
|
+
@configuration = defined?(@environment) ? config[@environment] : config
|
16
|
+
end
|
17
|
+
|
18
|
+
def configuration
|
19
|
+
if defined? @environment
|
20
|
+
raise RuntimeError.new("not configured CsvExporter for #{@environment} enviroment") unless @configuration
|
21
|
+
else
|
22
|
+
raise RuntimeError.new('not configured CsvExporter') unless @configuration
|
23
|
+
end
|
24
|
+
|
25
|
+
@configuration
|
26
|
+
end
|
27
|
+
|
28
|
+
def environment
|
29
|
+
@environment
|
30
|
+
end
|
31
|
+
|
32
|
+
def file(filename = nil)
|
33
|
+
filename ||= configuration['filename']
|
34
|
+
File.join(root, configuration['filepath'], filename)
|
35
|
+
end
|
36
|
+
|
37
|
+
def root
|
38
|
+
defined?(Rails) ? Rails.root : File.expand_path("../.." , __FILE__)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: csv_exporter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- DrawGun
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Simple solution to export csv file.
|
84
|
+
email:
|
85
|
+
- drawgunich@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- lib/csv_exporter/base.rb
|
91
|
+
- lib/csv_exporter/core_ext/active_support.rb
|
92
|
+
- lib/csv_exporter/core_ext/array.rb
|
93
|
+
- lib/csv_exporter/version.rb
|
94
|
+
- lib/csv_exporter.rb
|
95
|
+
- lib/tasks/csv_exporter_tasks.rake
|
96
|
+
- MIT-LICENSE
|
97
|
+
- Rakefile
|
98
|
+
- README.rdoc
|
99
|
+
homepage: https://github.com/DrawGun/csv_exporter
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.0.14
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Simple solution to export csv file.
|
123
|
+
test_files: []
|