Class: Aurfy::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Parser

Returns a new instance of Parser.



5
6
7
# File 'lib/aurfy/parser.rb', line 5

def initialize(body)
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

Instance Method Details

#parseObject



9
10
11
12
13
# File 'lib/aurfy/parser.rb', line 9

def parse
  params = body.split("&").map { |p| p.split("=") }
  params = params.map { |p| p.length >= 2 ? p : p.push("") }
  params.to_h.each_with_object({}) { |(k, v), a| a[k.to_s.to_sym] = v }
end