Class: HttpStreamFormat

Inherits:
Format
  • Object
show all
Defined in:
lib/httpstreamformat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content = nil, close = false) ⇒ HttpStreamFormat

Returns a new instance of HttpStreamFormat.



15
16
17
18
19
20
21
# File 'lib/httpstreamformat.rb', line 15

def initialize(content=nil, close=false)
  @content = content
  @close = close
  if !@close and @content.nil?
    raise 'Content not set'
  end
end

Instance Attribute Details

#closeObject

Returns the value of attribute close.



13
14
15
# File 'lib/httpstreamformat.rb', line 13

def close
  @close
end

#contentObject

Returns the value of attribute content.



12
13
14
# File 'lib/httpstreamformat.rb', line 12

def content
  @content
end

Instance Method Details

#exportObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/httpstreamformat.rb', line 27

def export
  out = Hash.new
  if @close
    out['action'] = 'close'
  else
    if @content.encoding.name == 'ASCII-8BIT'
      out['body-bin'] = Base64.encode64(@content)
    else
      out['body'] = @content
    end
  end
  return out
end

#nameObject



23
24
25
# File 'lib/httpstreamformat.rb', line 23

def name
  return 'http-stream'
end