Class: Cookie

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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(cookie_str)
  cookie_str.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

#expirationObject

Returns the value of attribute expiration.



30
31
32
# File 'lib/cookie_jar.rb', line 30

def expiration
  @expiration
end

#nameObject

Returns the value of attribute name.



30
31
32
# File 'lib/cookie_jar.rb', line 30

def name
  @name
end

#valueObject

Returns the value of attribute value.



30
31
32
# File 'lib/cookie_jar.rb', line 30

def value
  @value
end

Instance Method Details

#expiredObject



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_sObject



47
48
49
# File 'lib/cookie_jar.rb', line 47

def to_s
  "#{@name}=#{@value}"
end