Class: AngryMob::NotificationInspector

Inherits:
Object
  • Object
show all
Defined in:
lib/angry_mob/notifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scheduler, nickname, options = {}, &block) ⇒ NotificationInspector

Returns a new instance of NotificationInspector.



4
5
6
7
8
9
10
# File 'lib/angry_mob/notifier.rb', line 4

def initialize(scheduler,nickname,options={},&block)
  @scheduler,@nickname,@options = scheduler,nickname.to_s,options

  unless notifications.empty?
    yield_in_context(self,&block)
  end
end

Instance Attribute Details

#nicknameObject (readonly)

Returns the value of attribute nickname.



3
4
5
# File 'lib/angry_mob/notifier.rb', line 3

def nickname
  @nickname
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/angry_mob/notifier.rb', line 3

def options
  @options
end

Instance Method Details

#action?(*actions) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/angry_mob/notifier.rb', line 24

def action?(*actions)
  actions.norm!.all? {|action| notifications.any? {|n| n.actions.include?(action.to_s)}}
end

#notificationsObject



20
21
22
# File 'lib/angry_mob/notifier.rb', line 20

def notifications
  @notifications ||= @scheduler.notifications.select {|n| n.target == nickname}
end

#select_and_run_action(actions, &block) ⇒ Object



28
29
30
31
32
# File 'lib/angry_mob/notifier.rb', line 28

def select_and_run_action(actions, &block)
  if matched = actions.find {|action| action?(action)}
    yield_in_context matched, &block
  end
end

#yield_in_context(*args, &block) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/angry_mob/notifier.rb', line 12

def yield_in_context(*args,&block)
  if o = options[:context]
    o.instance_exec(*args,&block)
  else
    block.call(*args)
  end
end