Class: Cardigan::Command::ExportCards
- Inherits:
-
Object
- Object
- Cardigan::Command::ExportCards
- Defined in:
- lib/cardigan/command/export_cards.rb
Instance Attribute Summary collapse
-
#help ⇒ Object
readonly
Returns the value of attribute help.
-
#usage ⇒ Object
readonly
Returns the value of attribute usage.
Instance Method Summary collapse
- #execute(filename) ⇒ Object
-
#initialize(repository) ⇒ ExportCards
constructor
A new instance of ExportCards.
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
#help ⇒ Object (readonly)
Returns the value of attribute help.
5 6 7 |
# File 'lib/cardigan/command/export_cards.rb', line 5 def help @help end |
#usage ⇒ Object (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 |