Class: Lightstreamer::SubscriptionItemData

Inherits:
Object
  • Object
show all
Defined in:
lib/lightstreamer/subscription_item_data.rb

Overview

Helper class used by Subscription to process incoming item data according to the four different subscription modes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataHash, ...

The current item data. Item data is a hash for all subscription modes except ‘:command`, for which it is an array.

Returns:

  • (Hash, Array, nil)


10
11
12
# File 'lib/lightstreamer/subscription_item_data.rb', line 10

def data
  @data
end

Instance Method Details

#process_new_command_data(new_data) ⇒ Object

Processes new data for the ‘:command` subscription mode.

Parameters:

  • new_data (Hash)

    The new data.



28
29
30
31
32
33
34
35
# File 'lib/lightstreamer/subscription_item_data.rb', line 28

def process_new_command_data(new_data)
  @data ||= []

  key = row_key new_data
  command = new_data.delete(:command) || new_data.delete('command')

  send "process_#{command.to_s.downcase}_command", key, new_data
end

#process_new_distinct_data(new_data) ⇒ Object

Processes new data for the ‘:distinct` subscription mode.

Parameters:

  • new_data (Hash)

    The new data.



40
41
42
# File 'lib/lightstreamer/subscription_item_data.rb', line 40

def process_new_distinct_data(new_data)
  @data = new_data
end

#process_new_merge_data(new_data) ⇒ Object

Processes new data for the ‘:merge` subscription mode.

Parameters:

  • new_data (Hash)

    The new data.



47
48
49
50
# File 'lib/lightstreamer/subscription_item_data.rb', line 47

def process_new_merge_data(new_data)
  @data ||= {}
  @data.merge! new_data
end

#process_new_raw_data(new_data) ⇒ Object

Processes new data for the ‘:raw` subscription mode.

Parameters:

  • new_data (Hash)

    The new data.



55
56
57
# File 'lib/lightstreamer/subscription_item_data.rb', line 55

def process_new_raw_data(new_data)
  @data = new_data
end

#set_data(new_data, mode) ⇒ Object

Explicitly sets this item data. See Lightstreamer::Subscription#set_item_data for details.

Parameters:

  • new_data (Array, Hash)

    The new data for the item.

  • mode (:command, :merge)

    The subscription mode.

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
# File 'lib/lightstreamer/subscription_item_data.rb', line 16

def set_data(new_data, mode)
  raise ArgumentError, "Data can't be set unless mode is :command or :merge" unless %i[command merge].include? mode
  raise ArgumentError, 'Data must be a hash when in merge mode' if mode == :merge && !new_data.is_a?(Hash)

  validate_rows new_data if mode == :command

  @data = new_data.dup
end