Class: Cardigan::Command::FilterCards

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

Instance Attribute Summary

Attributes inherited from ListCards

#help, #usage

Instance Method Summary collapse

Constructor Details

#initialize(repository, io) ⇒ FilterCards

Returns a new instance of FilterCards.



4
5
6
7
8
# File 'lib/cardigan/command/filter_cards.rb', line 4

def initialize repository, io
  super
  @usage = '<ruby expression>'
  @help = "Sets the filter on cards to be displayed\nThis filter is a ruby expression that must return a boolean.\nBound variables are card (a hash) and me (a string)"
end

Instance Method Details

#execute(filter) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/cardigan/command/filter_cards.rb', line 10

def execute filter
  @repository.filter = filter
  begin
    super
  rescue Exception => e
    @io.say "Invalid expression:\n#{e.message}"
    @repository.filter = nil
  end
end