Web::Cookie Class

Class Methods

 -- Cookie::new()

      create new cookie.

Methods

 -- Cookie#match?(url)

       match cookie by url. if match, return true. otherwise,
       return false.

 -- Cookie#name
 -- Cookie#name=(name)
 -- Cookie#value
 -- Cookie#value=(value)
 -- Cookie#domain
 -- Cookie#domain=(domain)
 -- Cookie#path
 -- Cookie#path=(path)
 -- Cookie#expires
 -- Cookie#expires=(expires)
 -- Cookie#url
 -- Cookie#url=(url)

      accessor methods for cookie's items.

 -- Cookie#discard?
 -- Cookie#discard=(discard)
 -- Cookie#use?
 -- Cookie#use=(use)
 -- Cookie#secure?
 -- Cookie#secure=(secure)
 -- Cookie#domain_orig?
 -- Cookie#domain_orig=(domain_orig)
 -- Cookie#path_orig?
 -- Cookie#path_orig=(path_orig)
 -- Cookie#override?
 -- Cookie#override=(override)
 -- Cookie#flag
 -- Cookie#set_flag(flag_num)

      accessor methods for flags.
Methods
Included Modules
Constants
USE = 1
SECURE = 2
DOMAIN = 4
PATH = 8
DISCARD = 16
OVERRIDE = 32
OVERRIDE_OK = 32
Attributes
[W] discard
[RW] domain
[W] domain_orig
[RW] expires
[RW] name
[W] override
[RW] path
[W] path_orig
[W] secure
[RW] url
[W] use
[RW] value
Public Class methods
new()
# File lib/facets/more/cookie.rb, line 150
    def initialize()
      @discard = @use = @secure = @domain_orig = @path_orig = @override = nil
    end
Public Instance methods
discard?()
# File lib/facets/more/cookie.rb, line 154
    def discard?
      @discard
    end
domain_orig?()
# File lib/facets/more/cookie.rb, line 166
    def domain_orig?
      @domain_orig
    end
flag()
# File lib/facets/more/cookie.rb, line 178
    def flag
      flg = 0
      flg += USE  if @use
      flg += SECURE  if @secure
      flg += DOMAIN  if @domain_orig
      flg += PATH  if @path_orig
      flg += DISCARD if @discard
      flg += OVERRIDE if @override
      flg
    end
join_quotedstr(array, sep)
# File lib/facets/more/cookie.rb, line 211
    def join_quotedstr(array, sep)
      ret = Array.new()
      old_elem = nil
      array.each{|elem|
        if (elem.scan(/"/).length % 2) == 0
          if old_elem
            old_elem << sep << elem
          else
            ret << elem
            old_elem = nil
          end
        else
          if old_elem
            old_elem << sep << elem
            ret << old_elem
            old_elem = nil
          else
            old_elem = elem.dup
          end
        end
      }
      ret
    end
match?(url)
# File lib/facets/more/cookie.rb, line 199
    def match?(url)
      domainname = url.host
      if (!domainname ||
          !domain_match(domainname, @domain) ||
          (@path && !head_match?(@path, url.path)) ||
          (@secure && (url.scheme != 'https')) )
        return false
      else
        return true
      end
    end
override?()
# File lib/facets/more/cookie.rb, line 174
    def override?
      @override
    end
parse(str, url)
# File lib/facets/more/cookie.rb, line 235
    def parse(str, url)
      @url = url
      cookie_elem = str.split(/;/)
      cookie_elem = join_quotedstr(cookie_elem, ';')
      first_elem = cookie_elem.shift
      if first_elem !~ /([^=]*)(\=(.*))?/
        return
        ## raise ArgumentError 'invalid cookie value'
      end
      @name = $1.strip
      @value = $3
      if @value
        if @value =~ /^\s*"(.*)"\s*$/
          @value = $1
        else
          @value.dup.strip!
        end
      end
      cookie_elem.each{|pair|
        key, value = pair.split(/=/)  ## value may nil
        key.strip!
        if value
          value = value.strip.sub(/\A"(.*)"\z/) { $1 }
        end
        case key.downcase
        when 'domain'
          @domain = value
        when 'expires'
          begin
            @expires = Time.gm(*parsedate(value)[0,6])
          rescue ArgumentError
            @expires = nil
          end
        when 'path'
          @path = value
        when 'secure'
          @secure = true  ## value may nil, but must 'true'.
        else
          ## ignore
        end
      }
    end
path_orig?()
# File lib/facets/more/cookie.rb, line 170
    def path_orig?
      @path_orig
    end
secure?()
# File lib/facets/more/cookie.rb, line 162
    def secure?
      @secure
    end
set_flag(flag)
# File lib/facets/more/cookie.rb, line 189
    def set_flag(flag)
      flag = flag.to_i
      @use = true      if flag & USE > 0
      @secure = true   if flag & SECURE > 0
      @domain_orig = true if flag & DOMAIN > 0
      @path_orig = true if flag & PATH > 0
      @discard  = true if flag & DISCARD > 0
      @override = true if flag & OVERRIDE > 0
    end
use?()
# File lib/facets/more/cookie.rb, line 158
    def use?
      @use
    end