Class: Cardigan::Command::ExportCards

Inherits:
Object
  • Object
show all
Defined in:
lib/cardigan/command/export_cards.rb

Instance Method Summary collapse

Constructor Details

#initialize(repository) ⇒ ExportCards

Returns a new instance of ExportCards.



4
5
6
# File 'lib/cardigan/command/export_cards.rb', line 4

def initialize repository
  @repository = repository
end

Instance Method Details

#execute(filename) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/cardigan/command/export_cards.rb', line 8

def execute filename
  filename += ".csv"
  columns = @repository.columns
  CSV.open(filename, 'w') do |writer|
    writer << columns
    @repository.each do |card|
      writer << columns.map {|column| card[column] ? card[column] : ''}
    end
  end
end