Class: VkCozy::UserLabeler

Inherits:
Object
  • Object
show all
Defined in:
lib/vk_cozy/framework/labeler/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ UserLabeler

Returns a new instance of UserLabeler.



5
6
7
8
# File 'lib/vk_cozy/framework/labeler/user.rb', line 5

def initialize(api)
  @api = api
  @rules = []
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



3
4
5
# File 'lib/vk_cozy/framework/labeler/user.rb', line 3

def api
  @api
end

Instance Method Details

#filter(event_raw) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vk_cozy/framework/labeler/user.rb', line 10

def filter(event_raw)
  event = VkCozy::UserEvent.new(@api, event_raw)
  for i in @rules
    f = i[:filter]
    check = f.check_user(event)
    if check
      if check.is_a?(Symbol)
        check = [Symbol]
      elsif check.is_a?(Array)
        i[:func].call(event, *check)
      elsif check.is_a?(Hash)
        i[:func].call(event, **check)
      else
        i[:func].call(event)
      end
      return true
    end
	end
end

#message_handler(filter, func) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/vk_cozy/framework/labeler/user.rb', line 30

def message_handler(filter, func)
  if func.is_a?(Symbol)
    func = method(func)
  end
  @rules << { 
    :func => func,
    :filter => filter
  }
end