Class: HTTPal::Cookie

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/rspider/cookie.rb

Constant Summary collapse

@@fields =
[:path, :domain, :expires]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Cookie

Returns a new instance of Cookie.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rspider/cookie.rb', line 69

def initialize(string)
	components = string.split(';')
	firstpair = nil
	components.each do |p|
		sp = p.split('=',2)
		k = sp[0]
		v = sp[1]
		k.strip!
		v.strip!
		if firstpair == nil
			send(:name=, k)
			send(:value=, v)
			firstpair = true
		else
			next unless @@fields.include? k.downcase.to_sym
			v = v.gsub(/^\./,'') if k.downcase.to_sym == :domain
			send((k+'=').downcase.to_sym, v)
		end
	end
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



67
68
69
# File 'lib/rspider/cookie.rb', line 67

def name
  @name
end

#valueObject

Returns the value of attribute value.



67
68
69
# File 'lib/rspider/cookie.rb', line 67

def value
  @value
end

Instance Method Details

#<=>(anOther) ⇒ Object



103
104
105
106
107
108
109
110
111
# File 'lib/rspider/cookie.rb', line 103

def <=> (anOther)
	#sort by domain, then path, then name
	d = self.domain.<=>(anOther.domain)
	p = self.path.<=>(anOther.path)
	n = self.name.<=>(anOther.name)
	return d unless d == 0
	return p unless p == 0
	return n
end

#inspectObject



98
99
100
# File 'lib/rspider/cookie.rb', line 98

def inspect
	"\#<Cookie #{name}=#{value} from #{domain}#{path} until #{expires}>"
end

#to_sObject



90
91
92
93
94
95
96
# File 'lib/rspider/cookie.rb', line 90

def to_s
	r = "#{name}=#{value}"
	@@fields.each do |f|
		r << "; #{f.to_s}=#{send(f)}" if send(f)
	end
	return r
end