Class: Cleaver

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, header) ⇒ Cleaver

Returns a new instance of Cleaver.



5
6
7
8
# File 'lib/cleaver.rb', line 5

def initialize(params, header) 
  @header = header
  @params = params
end

Instance Attribute Details

#headerObject

Returns the value of attribute header.



3
4
5
# File 'lib/cleaver.rb', line 3

def header
  @header
end

#paramsObject

Returns the value of attribute params.



3
4
5
# File 'lib/cleaver.rb', line 3

def params
  @params
end

Class Method Details

.parse(client) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cleaver.rb', line 10

def self.parse(client)
  request_header = ''
  content_length_line = ''
  i = 0
  while i < 12
    line = client.gets 
    if line.include?("Content-Length")
      content_length_line = line
    end
      request_header += line
      i += 1
  end
  content_length = content_length_line.split(' ')[1].to_i
  params = {}
  params_string = client.read(content_length).split('&').each do |el|
    params_arr = el.split('=')
    params[params_arr[0].to_sym] = params_arr[1]
  end

  instance = new(params, request_header)

  return instance
end