Class: Redwood::Tagger

Inherits:
Object show all
Defined in:
lib/sup/tagger.rb

Instance Method Summary collapse

Constructor Details

#initialize(mode, noun = "thread", plural_noun = nil) ⇒ Tagger

Returns a new instance of Tagger.



6
7
8
9
10
11
# File 'lib/sup/tagger.rb', line 6

def initialize mode, noun="thread", plural_noun=nil
  @mode = mode
  @tagged = {}
  @noun = noun
  @plural_noun = plural_noun || (@noun + "s")
end

Instance Method Details

#apply_to_tagged(action = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sup/tagger.rb', line 20

def apply_to_tagged action=nil
  targets = @tagged.select_by_value
  num_tagged = targets.size
  if num_tagged == 0
    BufferManager.flash "No tagged threads!"
    return
  end

  noun = num_tagged == 1 ? @noun : @plural_noun

  unless action
    c = BufferManager.ask_getch "apply to #{num_tagged} tagged #{noun}:"
    return if c.empty? # user cancelled
    action = @mode.resolve_input c
  end

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

#drop_all_tagsObject



17
# File 'lib/sup/tagger.rb', line 17

def drop_all_tags; @tagged.clear; end

#drop_tag_for(o) ⇒ Object



18
# File 'lib/sup/tagger.rb', line 18

def drop_tag_for o; @tagged.delete o; end

#tag(o) ⇒ Object



15
# File 'lib/sup/tagger.rb', line 15

def tag o; @tagged[o] = true; end

#tagged?(o) ⇒ Boolean

Returns:

  • (Boolean)


13
# File 'lib/sup/tagger.rb', line 13

def tagged? o; @tagged[o]; end

#toggle_tag_for(o) ⇒ Object



14
# File 'lib/sup/tagger.rb', line 14

def toggle_tag_for o; @tagged[o] = !@tagged[o]; end

#untag(o) ⇒ Object



16
# File 'lib/sup/tagger.rb', line 16

def untag o; @tagged[o] = false; end