Class: FSR::Listener::Inbound::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/fsr/listener/inbound/event.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header = {}, body = {}) ⇒ Event

Returns a new instance of Event.



32
33
34
# File 'lib/fsr/listener/inbound/event.rb', line 32

def initialize(header = {}, body = {})
  @header, @body = header, body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



30
31
32
# File 'lib/fsr/listener/inbound/event.rb', line 30

def body
  @body
end

#headerObject (readonly)

Returns the value of attribute header.



30
31
32
# File 'lib/fsr/listener/inbound/event.rb', line 30

def header
  @header
end

Class Method Details

.from(data) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fsr/listener/inbound/event.rb', line 6

def self.from(data)
  instance = new

  capture = header = {}
  body = {}
  
  data.each_line do |line|
    line.strip!

  case line
    when ''
      capture = body
    when /([a-zA-Z0-9-]+):\s*(.*)/
      #capture[$1] = $2.strip
      key, val = line.split(":")
      capture[key] = val.to_s.strip
    end
  end
  
  instance.header.merge!(header)
  instance.body.merge!(body)
  instance
end

Instance Method Details

#[](key) ⇒ Object



36
37
38
# File 'lib/fsr/listener/inbound/event.rb', line 36

def [](key)
  @header.merge(@body)[key]
end