geetarista-export_csv 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.
- data/.gitignore +2 -0
- data/README.rdoc +11 -0
- data/lib/export_csv.rb +17 -0
- data/test/export_csv_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- metadata +69 -0
data/.gitignore
ADDED
data/README.rdoc
ADDED
data/lib/export_csv.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
def export_csv(klass, filename=klass, conditions="")
|
2
|
+
records = klass.find(:all, :conditions => conditions)
|
3
|
+
headers = klass.columns.collect{ |a| a.name }
|
4
|
+
data = []
|
5
|
+
records.each do |r|
|
6
|
+
record = []
|
7
|
+
headers.each do |h|
|
8
|
+
record << r[h]
|
9
|
+
end
|
10
|
+
data << record
|
11
|
+
end
|
12
|
+
table = Ruport::Data::Table(:column_names => headers.collect{ |h| h.humanize }, :data => data)
|
13
|
+
csv = table.to_csv
|
14
|
+
time = Time.now
|
15
|
+
filename = "#{filename}-#{time.strftime('%m%d%Y-%H%M')}.csv"
|
16
|
+
send_data csv, :filename => filename, :type => 'text/csv; charset=iso-8859-1; header=present', :disposition => "attachment; #{filename}"
|
17
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geetarista-export_csv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robby Colvin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-24 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ruport
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.6.1
|
24
|
+
version:
|
25
|
+
description: export_csv Gem
|
26
|
+
email:
|
27
|
+
- geetarista@gmail.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- README.rdoc
|
36
|
+
- .gitignore
|
37
|
+
- lib/export_csv.rb
|
38
|
+
- test/export_csv_test.rb
|
39
|
+
- test/test_helper.rb
|
40
|
+
has_rdoc: false
|
41
|
+
homepage: http://github.com/geetarista/export_csv
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options:
|
44
|
+
- --main
|
45
|
+
- README.rdoc
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.2.0
|
64
|
+
signing_key:
|
65
|
+
specification_version: 2
|
66
|
+
summary: none
|
67
|
+
test_files:
|
68
|
+
- test/export_csv_test.rb
|
69
|
+
- test/test_helper.rb
|