Class: Cookie
- Inherits:
-
Object
- Object
- Cookie
- Defined in:
- lib/cookie_jar.rb
Instance Attribute Summary collapse
-
#expiration ⇒ Object
Returns the value of attribute expiration.
-
#name ⇒ Object
Returns the value of attribute name.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #expired ⇒ Object
-
#initialize(cookie_str) ⇒ Cookie
constructor
A new instance of Cookie.
- #to_s ⇒ Object
Constructor Details
#initialize(cookie_str) ⇒ Cookie
Returns a new instance of Cookie.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cookie_jar.rb', line 32 def initialize() .split(/;\s?/).each_with_index do |c,i| if i==0 @name, *values = c.split("=") @value = values.join("=") else attr_name, *attr_values = c.split("=") attr_value = attr_values.join("=") if attr_name =~ /expires/i @expiration = attr_value end end end end |
Instance Attribute Details
#expiration ⇒ Object
Returns the value of attribute expiration.
30 31 32 |
# File 'lib/cookie_jar.rb', line 30 def expiration @expiration end |
#name ⇒ Object
Returns the value of attribute name.
30 31 32 |
# File 'lib/cookie_jar.rb', line 30 def name @name end |
#value ⇒ Object
Returns the value of attribute value.
30 31 32 |
# File 'lib/cookie_jar.rb', line 30 def value @value end |
Instance Method Details
#expired ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/cookie_jar.rb', line 51 def expired if @expiration @expiration.sub!(/^([a-zA-Z]+,)(\d)/) { |s| "#{$1} #{$2}" } expiration_date = DateTime.parse( @expiration, true ) return expiration_date < DateTime.now end false end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/cookie_jar.rb', line 47 def to_s "#{@name}=#{@value}" end |