Class: Arcp::Job::EventBody::ResultChunk
- Inherits:
-
Data
- Object
- Data
- Arcp::Job::EventBody::ResultChunk
- Defined in:
- lib/arcp/job/event_body/result_chunk.rb
Constant Summary collapse
- ENCODINGS =
%w[utf8 base64].freeze
Instance Attribute Summary collapse
-
#chunk_seq ⇒ Object
readonly
Returns the value of attribute chunk_seq.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
-
#more ⇒ Object
readonly
Returns the value of attribute more.
-
#result_id ⇒ Object
readonly
Returns the value of attribute result_id.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#chunk_seq ⇒ Object (readonly)
Returns the value of attribute chunk_seq
8 9 10 |
# File 'lib/arcp/job/event_body/result_chunk.rb', line 8 def chunk_seq @chunk_seq end |
#data ⇒ Object (readonly)
Returns the value of attribute data
8 9 10 |
# File 'lib/arcp/job/event_body/result_chunk.rb', line 8 def data @data end |
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding
8 9 10 |
# File 'lib/arcp/job/event_body/result_chunk.rb', line 8 def encoding @encoding end |
#more ⇒ Object (readonly)
Returns the value of attribute more
8 9 10 |
# File 'lib/arcp/job/event_body/result_chunk.rb', line 8 def more @more end |
#result_id ⇒ Object (readonly)
Returns the value of attribute 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
#decoded ⇒ Object
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_h ⇒ Object
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 |