Class: VkLongpollBot::Events::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/vk_longpoll_bot/events.rb

Overview

Class containing data received from longpoll. Provides easy access to it’s data.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subtype, data, group_id, bot) ⇒ Event

New event. Initialize from fields of update json and bot which got this event.

Parameters:

  • subtype (String)
  • data (Hash)

    update array entry.

  • group_id (Integer)
  • bot (Bot)


59
60
61
62
63
64
# File 'lib/vk_longpoll_bot/events.rb', line 59

def initialize(subtype, data, group_id, bot)
  @subtype = subtype.to_s
  @data = data
  @group_id = group_id.to_i
  @bot = bot
end

Instance Attribute Details

#botBot (readonly)

Returns longpoll bot which received event.

Returns:

  • (Bot)

    longpoll bot which received event.



50
51
52
# File 'lib/vk_longpoll_bot/events.rb', line 50

def bot
  @bot
end

#dataHash (readonly)

Returns hash with updates data.

Returns:

  • (Hash)

    hash with updates data.



46
47
48
# File 'lib/vk_longpoll_bot/events.rb', line 46

def data
  @data
end

#group_idInteger (readonly)

Returns ID of group which received event.

Returns:

  • (Integer)

    ID of group which received event.



42
43
44
# File 'lib/vk_longpoll_bot/events.rb', line 42

def group_id
  @group_id
end

#subtypeString (readonly)

Returns subtype of event.

Returns:

  • (String)

    subtype of event.



38
39
40
# File 'lib/vk_longpoll_bot/events.rb', line 38

def subtype
  @subtype
end

Instance Method Details

#[](arg) ⇒ Object

Provides access to fields of update data.

Parameters:

  • arg (String)

    hash key.

Returns:

  • (Object)


72
73
74
# File 'lib/vk_longpoll_bot/events.rb', line 72

def [](arg)
  @data[arg.to_s]
end