comma-heaven 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,6 +14,7 @@ module CommaHeaven
14
14
  def to_comma_heaven(options = {})
15
15
  options.symbolize_keys!
16
16
  options[:limit] = options[:limit].to_i if options[:limit].kind_of?(String)
17
+ options[:converter] ||= lambda { |v| v }
17
18
 
18
19
  FasterCSV::Table.new([]).tap do |table|
19
20
  columns = CommaHeaven::Sqler::Columns.new(self, options[:export])
@@ -21,7 +22,7 @@ module CommaHeaven
21
22
 
22
23
  find(:all, :limit => options[:limit], :joins => columns.joins, :select => columns.select).each do |resource|
23
24
  fields = columns.sql_as.inject([]) do |a, f|
24
- a << resource.send(f)
25
+ a << options[:converter].call(resource.send(f))
25
26
  end
26
27
 
27
28
  table << FasterCSV::Row.new(headers, fields)
@@ -180,6 +180,16 @@ EOS
180
180
  Name,Age,Position 0,Position 1
181
181
  Olmo,100,top,middle
182
182
  Ulivo,150,0,5
183
+ EOS
184
+ end
185
+
186
+ it "should export to CSV avoiding new lines in the fields" do
187
+ Tree.create(:name => "Ulivo\nGrande")
188
+ Tree.to_comma_heaven(:export => {:name => {0 => {}}, :age => {1 => {}}}, :converter => lambda { |v| v.to_s.gsub(/\n/, ' ') }).to_csv().should == <<-EOS
189
+ tree_name,tree_age
190
+ Olmo,100
191
+ Ulivo,150
192
+ Ulivo Grande,""
183
193
  EOS
184
194
  end
185
195
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comma-heaven
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 2
10
- version: 0.3.2
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Silvano Stralla
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-22 00:00:00 +02:00
18
+ date: 2010-12-09 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -112,8 +112,8 @@ homepage: http://github.com/sistrall/comma-heaven
112
112
  licenses: []
113
113
 
114
114
  post_install_message:
115
- rdoc_options:
116
- - --charset=UTF-8
115
+ rdoc_options: []
116
+
117
117
  require_paths:
118
118
  - lib
119
119
  required_ruby_version: !ruby/object:Gem::Requirement