Shared gem for creating csv files via decorator pattern
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
Gemfile
Gemfile.lock
README.md
decorated_csv.gemspec

README.md

Decorator CSV

This is a simple gem that lets you generate CSVs using the decorator pattern.

Requirements

This gem is compatible with ruby 1.9.3

This gem uses Draper as the decorator.

The decorator requires the following methods and constants to be available:

  • #as_csv_row
  • CSV_HEADER_ROW

How To Use

Firstly setup your Draper decorator with the required methods and constants. For example

class PersonDecorator < Draper::Decorator

  decorate :person

  CSV_HEADER_ROW = ['First Name', 'Last Name', 'Age']

  def as_csv_row
    [
      source.first_name,
      source.last_name,
      source.age
    ]
  end

end

Then call the generate method:

people = [person, another_person, third_person]
csv = DecoratedCSV.generate(PersonDecorator, people)