Class: Kinesis::Aggregation::Aggregator

Inherits:
Object
  • Object
show all
Defined in:
lib/kinesis/aggregation/aggregator.rb

Constant Summary collapse

MAGIC =
"\xf3\x89\x9a\xc2".force_encoding('ASCII-8BIT').freeze

Instance Method Summary collapse

Constructor Details

#initializeAggregator

Returns a new instance of Aggregator.



6
7
8
# File 'lib/kinesis/aggregation/aggregator.rb', line 6

def initialize
  @user_records = []
end

Instance Method Details

#add_user_record(user_record) ⇒ Object



10
11
12
# File 'lib/kinesis/aggregation/aggregator.rb', line 10

def add_user_record(user_record)
  @user_records << user_record
end

#aggregate!Object



14
15
16
17
18
19
20
21
22
# File 'lib/kinesis/aggregation/aggregator.rb', line 14

def aggregate!
  result = {
    partition_key: @user_records.first[:partition_key],
    explicit_hash_key: @user_records.first[:explicit_hash_key] || '',
    data: Base64.encode64(data)
  }
  @user_records = []
  result
end

#num_user_recordsObject



24
25
26
# File 'lib/kinesis/aggregation/aggregator.rb', line 24

def num_user_records
  @user_records.length
end