Class: Cardigan::Command::ExportCards

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository) ⇒ ExportCards

Returns a new instance of ExportCards.



7
8
9
10
11
# File 'lib/cardigan/command/export_cards.rb', line 7

def initialize repository
  @repository = repository
  @usage = '<filename>'
  @help = 'Exports all cards according to the current filter'
end

Instance Attribute Details

#helpObject (readonly)

Returns the value of attribute help.



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

def help
  @help
end

#usageObject (readonly)

Returns the value of attribute usage.



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

def usage
  @usage
end

Instance Method Details

#execute(filename) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/cardigan/command/export_cards.rb', line 13

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