Class: Klomp::Frames::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/klomp/frames.rb

Direct Known Subclasses

Connect, Disconnect, Send, ServerFrame, Subscribe, Unsubscribe

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



14
# File 'lib/klomp/frames.rb', line 14

def [](key);          headers[key];             end

#[]=(key, value) ⇒ Object



15
# File 'lib/klomp/frames.rb', line 15

def []=(key, value);  headers[key] = value;     end

#bodyObject



17
# File 'lib/klomp/frames.rb', line 17

def body; @body ||= ""; end

#body=(b) ⇒ Object



18
# File 'lib/klomp/frames.rb', line 18

def body=(b); @body = b; end

#dump_headersObject



24
25
26
27
28
# File 'lib/klomp/frames.rb', line 24

def dump_headers
  headers.map do |pair|
    pair.map {|x| x.to_s.gsub("\n","\\n").gsub(":","\\c").gsub("\\", "\\\\") }.join(':')
  end.join("\n").tap {|s| s << "\n" unless s.empty? }
end

#headersObject



13
# File 'lib/klomp/frames.rb', line 13

def headers;          @headers ||= new_headers; end

#nameObject



6
# File 'lib/klomp/frames.rb', line 6

def name; @name ||= self.class.name.split('::').last.upcase; end

#new_headersObject



8
9
10
11
# File 'lib/klomp/frames.rb', line 8

def new_headers
  # Dependency injection point for tests.
  {}
end

#stringify_headers(hdrs) ⇒ Object



30
31
32
33
34
# File 'lib/klomp/frames.rb', line 30

def stringify_headers(hdrs)
  new_hdrs = {}
  hdrs.each { |k, v| new_hdrs[k.to_s] = v }
  new_hdrs
end

#to_sObject



20
21
22
# File 'lib/klomp/frames.rb', line 20

def to_s
  "#{name}\n#{dump_headers}\n#{@body}#{FRAME_SEP}"
end