kama 0.0.1 → 0.5.0

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/.rvmrc +2 -0
  2. data/lib/kama.rb +30 -2
  3. data/lib/kama/version.rb +2 -2
  4. metadata +3 -2
data/.rvmrc ADDED
@@ -0,0 +1,2 @@
1
+ RVM_STRING="rvm use ruby-1.9.3-p327@kama --create --verbose"
2
+ [ -e './.rvmrc_local' ] && source './.rvmrc_local' || $RVM_STRING
data/lib/kama.rb CHANGED
@@ -1,5 +1,33 @@
1
1
  require "kama/version"
2
+ require 'forwardable'
3
+ require 'csv'
2
4
 
3
- module Kama
4
- # Your code goes here...
5
+ class Kama
6
+ extend Forwardable
7
+
8
+ # @param data Either a AR class, or collection of AR objects.
9
+ # @return [String] A csv-string containing all the data given (defaulting to #all)
10
+ def self.dump(data, *args)
11
+ if data.is_a?(Class)
12
+ new(data, data.all)
13
+ else
14
+ new(data.class, data)
15
+ end.to_csv(*args)
16
+ end
17
+
18
+ def initialize(klass, data)
19
+ @klass = klass
20
+ @data = data
21
+ end
22
+ delegate :column_names => :@klass
23
+
24
+ def to_csv(io = "")
25
+ io << CSV.generate do |output|
26
+ output << column_names
27
+
28
+ @data.each do |obj|
29
+ output << column_names.map { |c| obj.send(c) }
30
+ end
31
+ end
32
+ end
5
33
  end
data/lib/kama/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module Kama
2
- VERSION = "0.0.1"
1
+ class Kama
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kama
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-03 00:00:00.000000000 Z
12
+ date: 2013-03-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Converts AR models to CSV
15
15
  email:
@@ -19,6 +19,7 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - .gitignore
22
+ - .rvmrc
22
23
  - Gemfile
23
24
  - LICENSE.txt
24
25
  - README.md