comma-heaven 0.4.0 → 0.4.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.
@@ -21,8 +21,14 @@ module CommaHeaven
|
|
21
21
|
headers = columns.sql_as
|
22
22
|
|
23
23
|
find(:all, :limit => options[:limit], :joins => columns.joins, :select => columns.select).each do |resource|
|
24
|
-
fields = columns.sql_as.inject([]) do |
|
25
|
-
|
24
|
+
fields = columns.sql_as.inject([]) do |acc, field|
|
25
|
+
value = resource.send(field)
|
26
|
+
|
27
|
+
if options[:format]
|
28
|
+
value = value.to_time.strftime(options[:format][:datetime]) if value =~ %r{(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)} && options[:format][:datetime]
|
29
|
+
end
|
30
|
+
|
31
|
+
acc << options[:converter].call(value)
|
26
32
|
end
|
27
33
|
|
28
34
|
table << FasterCSV::Row.new(headers, fields)
|
@@ -2,8 +2,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
|
3
3
|
describe "CommaHeaven" do
|
4
4
|
before(:each) do
|
5
|
-
alice = Gardener.create(:name => 'Alice')
|
6
|
-
bob = Gardener.create(:name => 'Bob')
|
5
|
+
alice = Gardener.create(:name => 'Alice', :birthdate => 6.years.ago)
|
6
|
+
bob = Gardener.create(:name => 'Bob', :birthdate => 8.years.ago)
|
7
7
|
|
8
8
|
olmo = Tree.create(:name => 'Olmo', :age => 100, :gardener => alice)
|
9
9
|
olmo.leafs.create(:position => 'top')
|
@@ -192,4 +192,13 @@ Ulivo,150
|
|
192
192
|
Ulivo Grande,""
|
193
193
|
EOS
|
194
194
|
end
|
195
|
+
|
196
|
+
it "should allow custom formats on dates and times" do
|
197
|
+
Tree.to_comma_heaven(:format => {:datetime => '%d/%m/%Y %H:%M'}, :export => {:name => {0 => {}}, :gardener => {1 => {:export => {:name => {1 => {}}, :surname => {2 => {}}, :birthdate => {3 => {}}}}}}).to_csv.should == <<-EOS
|
198
|
+
tree_name,gardener_name,gardener_surname,gardener_birthdate
|
199
|
+
Olmo,Alice,,#{Gardener.find_by_name('Alice').birthdate.strftime('%d/%m/%Y %H:%M')}
|
200
|
+
Ulivo,Bob,,#{Gardener.find_by_name('Bob').birthdate.strftime('%d/%m/%Y %H:%M')}
|
201
|
+
EOS
|
202
|
+
end
|
203
|
+
|
195
204
|
end
|
data/spec/spec_helper.rb
CHANGED
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:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 1
|
10
|
+
version: 0.4.1
|
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:
|
18
|
+
date: 2011-01-14 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|