Class: HTTPal::Cookie
- Inherits:
-
Object
- Object
- HTTPal::Cookie
- Includes:
- Comparable
- Defined in:
- lib/rspider/cookie.rb
Constant Summary collapse
- @@fields =
[:path, :domain, :expires]
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #<=>(anOther) ⇒ Object
-
#initialize(string) ⇒ Cookie
constructor
A new instance of Cookie.
- #inspect ⇒ Object
- #to_s ⇒ Object
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
#name ⇒ Object
Returns the value of attribute name.
67 68 69 |
# File 'lib/rspider/cookie.rb', line 67 def name @name end |
#value ⇒ Object
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 |
#inspect ⇒ Object
98 99 100 |
# File 'lib/rspider/cookie.rb', line 98 def inspect "\#<Cookie #{name}=#{value} from #{domain}#{path} until #{expires}>" end |
#to_s ⇒ Object
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 |