Class: StompPublisher::Header

Inherits:
Object
  • Object
show all
Includes:
Net::HTTPHeader
Defined in:
lib/stomp_publisher/header.rb

Constant Summary collapse

ESCAPES =
{
  "\\" => "\\\\",
  "\r" => "\\r",
  "\n" => "\\n",
  ":"  => "\\c",
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers = {}) ⇒ Header

Returns a new instance of Header.



22
23
24
# File 'lib/stomp_publisher/header.rb', line 22

def initialize(headers = {})
  initialize_http_header(headers)
end

Class Method Details

.parse(header_text) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/stomp_publisher/header.rb', line 14

def self.parse(header_text)
  header = self.new
  header_text.each_line do |line|
    header.add_field(*line.chomp.split(":", 2))
  end
  header
end

Instance Method Details

#decode(value) ⇒ Object



36
37
38
# File 'lib/stomp_publisher/header.rb', line 36

def decode(value)
  ESCAPES.inject(value.to_s) { |value, (from, to)| value.gsub(to, from) }
end

#encode(value) ⇒ Object



32
33
34
# File 'lib/stomp_publisher/header.rb', line 32

def encode(value)
  ESCAPES.inject(value.to_s) { |value, (from, to)| value.gsub(from, to) }
end

#to_sObject



26
27
28
29
30
# File 'lib/stomp_publisher/header.rb', line 26

def to_s
  each_name.flat_map do |key|
    get_fields(key).map { |value| "#{encode(key)}:#{encode(value)}" }
  end * "\n"
end