Class: Cardigan::Command::CountCards
- Inherits:
-
Object
- Object
- Cardigan::Command::CountCards
- Defined in:
- lib/cardigan/command/count_cards.rb
Instance Method Summary collapse
- #execute(text) ⇒ Object
-
#initialize(repository, io) ⇒ CountCards
constructor
A new instance of CountCards.
Constructor Details
#initialize(repository, io) ⇒ CountCards
Returns a new instance of CountCards.
2 3 4 |
# File 'lib/cardigan/command/count_cards.rb', line 2 def initialize repository, io @repository, @io = repository, io end |
Instance Method Details
#execute(text) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/cardigan/command/count_cards.rb', line 6 def execute text grouping_fields = text.scan(/\w+/) counts = {} @repository.cards.each do |card| key = grouping_fields.map {|key| card[key] ? card[key] : ''} counts[key] = counts[key] ? counts[key] + 1 : 1 end counts.keys.sort.each {|key| @io.say "#{counts[key]} #{key.inspect}"} end |