Class: Wpxf::Net::CookieJar

Inherits:
Hash
  • Object
show all
Defined in:
lib/wpxf/net/cookie_jar.rb

Overview

A Hash derivitive that provides cookie parsing functionality.

Instance Method Summary collapse

Instance Method Details

#parse(cookies) ⇒ CookieJar

Parse one or more cookies into the Wpxf::Net::CookieJar.

Parameters:

  • cookies (Array, String)

    the cookies to parse.

Returns:



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wpxf/net/cookie_jar.rb', line 24

def parse(cookies)
  return self if cookies.nil?

  if cookies.is_a? String
    parse_cookie(cookies)
  else
    cookies.each { |s| parse_cookie(s) }
  end

  self
end

Parse a cookie into the Wpxf::Net::CookieJar.

Parameters:

  • cookie (String)

    the cookie to parse.

Returns:



15
16
17
18
19
# File 'lib/wpxf/net/cookie_jar.rb', line 15

def parse_cookie(cookie)
  key, value = cookie.split('; ').first.split('=', 2)
  self[key] = value
  self
end

#to_sString

Returns a cookie string.

Returns:

  • (String)

    a cookie string.



8
9
10
# File 'lib/wpxf/net/cookie_jar.rb', line 8

def to_s
  map { |key, value| "#{key}=#{value};" }.join(' ')
end