Class: VkCozy::UserLabeler
- Inherits:
-
Object
- Object
- VkCozy::UserLabeler
- Defined in:
- lib/vk_cozy/framework/labeler/user.rb
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
Instance Method Summary collapse
- #add_handler(filter, func, type: '*') ⇒ Object
- #filter(event_raw) ⇒ Object
- #get_handlers(type) ⇒ Object
- #handler(filter, func) ⇒ Object
-
#initialize(api) ⇒ UserLabeler
constructor
A new instance of UserLabeler.
- #message_handler(filter, func) ⇒ Object
Constructor Details
#initialize(api) ⇒ UserLabeler
Returns a new instance of UserLabeler.
31 32 33 34 |
# File 'lib/vk_cozy/framework/labeler/user.rb', line 31 def initialize(api) @api = api @handlers = {'*' => []} end |
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
29 30 31 |
# File 'lib/vk_cozy/framework/labeler/user.rb', line 29 def api @api end |
Instance Method Details
#add_handler(filter, func, type: '*') ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/vk_cozy/framework/labeler/user.rb', line 54 def add_handler(filter, func, type: '*') if func.is_a?(Symbol) func = method(func) end if @handlers[type].nil? @handlers[type] = [] end @handlers[type] << UserHandler.new(filter, func) end |
#filter(event_raw) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/vk_cozy/framework/labeler/user.rb', line 44 def filter(event_raw) event = VkCozy::UserEvent.new(@api, event_raw) puts event for handler in get_handlers(event.type) + get_handlers('*') if handler.check(event) return true end end end |
#get_handlers(type) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/vk_cozy/framework/labeler/user.rb', line 36 def get_handlers(type) if @handlers[type].nil? return [] else return @handlers[type] end end |
#handler(filter, func) ⇒ Object
70 71 72 |
# File 'lib/vk_cozy/framework/labeler/user.rb', line 70 def handler(filter, func) add_handler(filter, func) end |
#message_handler(filter, func) ⇒ Object
66 67 68 |
# File 'lib/vk_cozy/framework/labeler/user.rb', line 66 def (filter, func) add_handler(filter, func, type: VkCozy::UserEventType::MESSAGE_NEW) end |