to_csv-rails 0.1.1 → 0.1.2

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.
Files changed (4) hide show
  1. data/CHANGELOG +4 -1
  2. data/VERSION +1 -1
  3. data/lib/to_csv-rails.rb +11 -6
  4. metadata +20 -27
data/CHANGELOG CHANGED
@@ -2,4 +2,7 @@
2
2
  first commit
3
3
 
4
4
  0.1.1
5
- update document
5
+ update document
6
+
7
+ 0.1.2
8
+ added custom header column names
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -1,24 +1,29 @@
1
1
  class Array
2
-
2
+
3
3
  def to_csv(options = {})
4
4
  return '' if self.empty?
5
5
 
6
+ options.reverse_merge!(:header => true)
7
+
6
8
  #columns = self.first.class.content_columns # not include the ID column
7
9
  if options[:only]
8
10
  columns = Array(options[:only]).map(&:to_sym)
9
11
  else
10
12
  columns = self.first.class.column_names.map(&:to_sym) - Array(options[:except]).map(&:to_sym)
11
13
  end
12
-
14
+
13
15
  return '' if columns.empty?
14
-
16
+
15
17
  data = []
16
18
  # header
17
- data << columns.map(&:to_s).map(&:humanize).join(', ') unless options[:header] == false
19
+ if options[:header]
20
+ data << options[:header_columns].blank? ? columns.map(&:to_s).map(&:humanize).join(',') : options[:header_columns]
21
+ end
22
+
18
23
  self.each do |obj|
19
- data << columns.map{ |column| obj.send(column) }.join(', ')
24
+ data << columns.map{ |column| obj.send(column) }.join(',')
20
25
  end
21
26
  data.join("\n")
22
27
  end
23
-
28
+
24
29
  end
metadata CHANGED
@@ -1,27 +1,24 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: to_csv-rails
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
4
5
  prerelease:
5
- version: 0.1.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - LiangWenKe
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-06-01 00:00:00 Z
12
+ date: 2013-03-23 00:00:00.000000000 Z
14
13
  dependencies: []
15
-
16
- description: This simple plugin gives you the ability to call to_csv to a collection of activerecords. The builder options are the same as to_json / to_xml, except for the :include.
14
+ description: This simple plugin gives you the ability to call to_csv to a collection
15
+ of activerecords. The builder options are the same as to_json / to_xml, except for
16
+ the :include.
17
17
  email: liangwenke.com@gmail.com
18
18
  executables: []
19
-
20
19
  extensions: []
21
-
22
20
  extra_rdoc_files: []
23
-
24
- files:
21
+ files:
25
22
  - lib/to_csv-rails.rb
26
23
  - CHANGELOG
27
24
  - init.rb
@@ -32,30 +29,26 @@ files:
32
29
  - VERSION
33
30
  homepage: http://github.com/liangwenke/to_csv-rails
34
31
  licenses: []
35
-
36
32
  post_install_message:
37
33
  rdoc_options: []
38
-
39
- require_paths:
34
+ require_paths:
40
35
  - lib
41
- required_ruby_version: !ruby/object:Gem::Requirement
36
+ required_ruby_version: !ruby/object:Gem::Requirement
42
37
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: "0"
47
- required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
43
  none: false
49
- requirements:
50
- - - ">="
51
- - !ruby/object:Gem::Version
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
52
47
  version: 1.3.4
53
48
  requirements: []
54
-
55
49
  rubyforge_project:
56
- rubygems_version: 1.8.5
50
+ rubygems_version: 1.8.25
57
51
  signing_key:
58
52
  specification_version: 3
59
53
  summary: Export data to csv on Rails
60
54
  test_files: []
61
-