excelizer 0.0.7
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/README_ES.md +1 -0
- data/Rakefile +1 -0
- data/excelizer.gemspec +25 -0
- data/lib/excelizer/version.rb +3 -0
- data/lib/excelizer/writer.rb +22 -0
- data/lib/excelizer.rb +52 -0
- data/test/spec.rb +0 -0
- metadata +107 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Arturo Puente
|
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,29 @@
|
|
1
|
+
# Excelizer
|
2
|
+
|
3
|
+
Excelizer handles Excel files generation for your Rails application using the Spreadsheet gem.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'excelizer'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install excelizer
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/README_ES.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Pendiente
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/excelizer.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'excelizer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "excelizer"
|
8
|
+
spec.version = Excelizer::VERSION
|
9
|
+
spec.authors = ["Arturo Puente"]
|
10
|
+
spec.email = ["arturopuentevc@gmail.com"]
|
11
|
+
spec.description = "An Excel helper for Rails project. It integrates with ActiveRecord models and other space magic."
|
12
|
+
spec.summary = "An Excel helper for Rails project"
|
13
|
+
spec.homepage = "https://github.com/arturopuente/excelizer"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "spreadsheet"
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Excelizer
|
2
|
+
class Writer
|
3
|
+
require 'spreadsheet' unless defined?(Spreadsheet)
|
4
|
+
|
5
|
+
def self.write(headers, records)
|
6
|
+
book = Spreadsheet::Workbook.new
|
7
|
+
sheet = book.create_worksheet
|
8
|
+
|
9
|
+
sheet.row(0).push *headers
|
10
|
+
records.each_with_index do |record, index|
|
11
|
+
sheet.row(index + 1).push *record
|
12
|
+
end
|
13
|
+
|
14
|
+
self.persist book
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.persist(book, file=StringIO.new)
|
18
|
+
book.write file
|
19
|
+
file.string
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/excelizer.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "excelizer/version"
|
2
|
+
require "excelizer/writer"
|
3
|
+
|
4
|
+
module Excelizer
|
5
|
+
class Base
|
6
|
+
def self.attr_downloadable(*attrs)
|
7
|
+
attrs.each do |attr|
|
8
|
+
define_method(attr) do
|
9
|
+
eval "@#{attr}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def build_xls(collection=model_class.all)
|
15
|
+
headers = *methods.select { |m| self.method(m).owner == self.class }.map { |m| m.to_s.titleize }
|
16
|
+
records = get_collection_data(collection)
|
17
|
+
|
18
|
+
Excelizer::Writer.write headers, records
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_collection_data(collection=model_class.all)
|
22
|
+
model_methods = model_clean_attributes model_class
|
23
|
+
|
24
|
+
# Gets the methods in the class definition and attr_downloadable
|
25
|
+
own_methods = methods.select { |m| self.method(m).owner == self.class }
|
26
|
+
|
27
|
+
# If the model class has the same method as the one defined in
|
28
|
+
# attr_downloadble, that method will be called.
|
29
|
+
collection.map do |child_instance|
|
30
|
+
@model = child_instance
|
31
|
+
own_methods.map do |attr|
|
32
|
+
# Checks if the model has a method with the same name and
|
33
|
+
# if the class definition overrides the model method
|
34
|
+
reciever = self
|
35
|
+
if model_methods.include?(attr.to_s) && reciever.send(attr).nil?
|
36
|
+
reciever = child_instance
|
37
|
+
end
|
38
|
+
reciever.send(attr)
|
39
|
+
end.compact
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def model_class
|
44
|
+
Object.const_get self.class.name.gsub "Downloader", ""
|
45
|
+
end
|
46
|
+
|
47
|
+
def model_clean_attributes(model_class_ref)
|
48
|
+
model_class_ref.new.attributes.keys - model_class_ref.protected_attributes.to_a
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
data/test/spec.rb
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: excelizer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Arturo Puente
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
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: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
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: spreadsheet
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
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: An Excel helper for Rails project. It integrates with ActiveRecord models
|
63
|
+
and other space magic.
|
64
|
+
email:
|
65
|
+
- arturopuentevc@gmail.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- README_ES.md
|
75
|
+
- Rakefile
|
76
|
+
- excelizer.gemspec
|
77
|
+
- lib/excelizer.rb
|
78
|
+
- lib/excelizer/version.rb
|
79
|
+
- lib/excelizer/writer.rb
|
80
|
+
- test/spec.rb
|
81
|
+
homepage: https://github.com/arturopuente/excelizer
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.23
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: An Excel helper for Rails project
|
106
|
+
test_files:
|
107
|
+
- test/spec.rb
|