Sha256: d627558ecb528a3b01a221c0fda3a8ee666846f376bd4d0507daf82a45ac0eb8

Contents?: true

Size: 996 Bytes

Versions: 8

Compression:

Stored size: 996 Bytes

Contents

module Redwood

class Tagger
  def initialize mode
    @mode = mode
    @tagged = {}
  end

  def tagged? o; @tagged[o]; end
  def toggle_tag_for o; @tagged[o] = !@tagged[o]; end
  def drop_all_tags; @tagged.clear; end
  def drop_tag_for o; @tagged.delete o; end

  def apply_to_tagged
    num_tagged = @tagged.map { |t| t ? 1 : 0 }.sum
    if num_tagged == 0
      BufferManager.flash "No tagged messages!"
      return
    end

    noun = num_tagged == 1 ? "message" : "messages"
    c = BufferManager.ask_getch "apply to #{num_tagged} tagged #{noun}:"
    return if c.nil? # user cancelled

    if(action = @mode.resolve_input c)
      tagged_sym = "multi_#{action}".intern
      if @mode.respond_to? tagged_sym
        targets = @tagged.select_by_value
        @mode.send tagged_sym, targets
      else
        BufferManager.flash "That command cannot be applied to multiple messages."
      end
    else
      BufferManager.flash "Unknown command #{c.to_character}."
    end
  end

end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sup-0.0.7 lib/sup/tagger.rb
sup-0.0.4 lib/sup/tagger.rb
sup-0.0.8 lib/sup/tagger.rb
sup-0.0.2 lib/sup/tagger.rb
sup-0.0.3 lib/sup/tagger.rb
sup-0.0.5 lib/sup/tagger.rb
sup-0.0.1 lib/sup/tagger.rb
sup-0.0.6 lib/sup/tagger.rb