Class: Arcp::Job::EventBody::ResultChunk

Inherits:
Data
  • Object
show all
Defined in:
lib/arcp/job/event_body/result_chunk.rb

Constant Summary collapse

ENCODINGS =
%w[utf8 base64].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#chunk_seqObject (readonly)

Returns the value of attribute chunk_seq

Returns:

  • (Object)

    the current value of chunk_seq



8
9
10
# File 'lib/arcp/job/event_body/result_chunk.rb', line 8

def chunk_seq
  @chunk_seq
end

#dataObject (readonly)

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



8
9
10
# File 'lib/arcp/job/event_body/result_chunk.rb', line 8

def data
  @data
end

#encodingObject (readonly)

Returns the value of attribute encoding

Returns:

  • (Object)

    the current value of encoding



8
9
10
# File 'lib/arcp/job/event_body/result_chunk.rb', line 8

def encoding
  @encoding
end

#moreObject (readonly)

Returns the value of attribute more

Returns:

  • (Object)

    the current value of more



8
9
10
# File 'lib/arcp/job/event_body/result_chunk.rb', line 8

def more
  @more
end

#result_idObject (readonly)

Returns the value of attribute result_id

Returns:

  • (Object)

    the current value of result_id



8
9
10
# File 'lib/arcp/job/event_body/result_chunk.rb', line 8

def result_id
  @result_id
end

Class Method Details

.from_h(h) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/arcp/job/event_body/result_chunk.rb', line 11

def self.from_h(h)
  h = h.transform_keys(&:to_s)
  encoding = h.fetch('encoding')
  unless ENCODINGS.include?(encoding)
    raise Arcp::Errors::InvalidRequest,
          "unknown encoding: #{encoding.inspect}"
  end

  new(
    result_id: h.fetch('result_id'),
    chunk_seq: h.fetch('chunk_seq'),
    data: h.fetch('data'),
    encoding: encoding,
    more: h.fetch('more')
  )
end

Instance Method Details

#decodedObject



33
34
35
36
37
38
# File 'lib/arcp/job/event_body/result_chunk.rb', line 33

def decoded
  case encoding
  when 'utf8'   then data
  when 'base64' then Base64.decode64(data)
  end
end

#to_hObject



28
29
30
31
# File 'lib/arcp/job/event_body/result_chunk.rb', line 28

def to_h
  { 'result_id' => result_id, 'chunk_seq' => chunk_seq, 'data' => data,
    'encoding' => encoding, 'more' => more }
end