crafterm-comma 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -109,6 +109,10 @@ You can specify which output format you would like to use via an optional parame
109
109
 
110
110
  Specifying no description name to to_comma is equivalent to specifying :default as the description name.
111
111
 
112
+ You can pass options for FasterCVS, e.g.
113
+
114
+ Book.limited(10).to_comma(:style => :brief, :col_sep => ';', :force_quotes => true)
115
+
112
116
  When used with Rails (ie. add 'comma' as a gem dependency), Comma automatically adds support for rendering CSV output in your controllers:
113
117
 
114
118
  class BooksController < ApplicationController
@@ -13,8 +13,8 @@ module Comma
13
13
  @results
14
14
  end
15
15
 
16
- def id
17
- method_missing(:id)
16
+ def id(*args)
17
+ method_missing(:id, *args)
18
18
  end
19
19
  end
20
20
 
data/lib/comma.rb CHANGED
@@ -4,9 +4,16 @@ require 'comma/extractors'
4
4
 
5
5
  class Array
6
6
  def to_comma(style = :default)
7
- FasterCSV.generate do |csv|
7
+ options = {}
8
+
9
+ if style.is_a? Hash
10
+ options = style
11
+ style = options.delete(:style)||:default
12
+ end
13
+
14
+ FasterCSV.generate(options) do |csv|
8
15
  return "" if empty?
9
- csv << first.to_comma_headers(style)
16
+ csv << first.to_comma_headers(style) # REVISIT: request to optionally include headers
10
17
  each do |object|
11
18
  csv << object.to_comma(style)
12
19
  end
@@ -42,7 +49,7 @@ if defined?(ActionController)
42
49
 
43
50
  module InstanceMethods
44
51
  def render_with_csv(options = nil, extra_options = {}, &block)
45
- return render_without_csv(options, extra_options, &block) unless (options.respond_to? '[]') and options[:csv]
52
+ return render_without_csv(options, extra_options, &block) unless options.is_a?(Hash) and options[:csv]
46
53
  data = options.delete(:csv)
47
54
  style = options.delete(:style) || :default
48
55
  send_data Array(data).to_comma(style), options.merge(:type => :csv)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crafterm-comma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcus Crafter