Module: CookieMonster

Defined in:
lib/cookiemonster.rb,
lib/cookiemonster/version.rb

Defined Under Namespace

Classes: Cookie

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.parse(set_cookie_string) ⇒ Object



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

def self.parse(set_cookie_string)
  Cookie.new self.parse_hash(set_cookie_string)
end

.parse_hash(set_cookie_string) ⇒ Object



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

def self.parse_hash(set_cookie_string)
  hash = set_cookie_string.split(/; ?/).inject({}) do |result, field|
    field_name, field_value = field.split('=', 2)
    result[field_name] = field_value
    result
  end

  name, value = hash.shift

  hash[:name] = name
  hash[:value] = value

  hash = hash.inject({}) do |options, (key, value)|
    options[(key.downcase.to_sym rescue key) || key] = value
    options
  end

  hash
end