Class: Cleaver
- Inherits:
-
Object
- Object
- Cleaver
- Defined in:
- lib/cleaver.rb
Instance Attribute Summary collapse
-
#header ⇒ Object
Returns the value of attribute header.
-
#params ⇒ Object
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params, header) ⇒ Cleaver
constructor
A new instance of Cleaver.
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
#header ⇒ Object
Returns the value of attribute header.
3 4 5 |
# File 'lib/cleaver.rb', line 3 def header @header end |
#params ⇒ Object
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 |