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



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

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

#[]=(key, value) ⇒ Object



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

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

#bodyObject



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

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

#body=(b) ⇒ Object



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

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

#dump_headersObject



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

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



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

def headers;         @headers ||= {};       end

#nameObject



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

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

#to_sObject



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

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