Class: RHACK::Cookie
Instance Method Summary collapse
-
#initialize(*args) ⇒ Cookie
constructor
A new instance of Cookie.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #use(str, uri) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Cookie
Returns a new instance of Cookie.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rhack/cookie.rb', line 7 def initialize(*args) if args[1].is Scout str, scout = *args ck = str//;\s*/ ck[1..-1].each {|par| a = par/'=' case a[0].downcase when 'path'; @path = (a[1] == '/') ? // : /^#{Regexp.escape a[1]}/ when 'domain'; @domain = /(^|\.)#{Regexp.escape a[1].sub(/^./, '')}$/ when 'expires'; @expires = a[1].to_time end } @name, @value = ck[0].split('=', 2) #@value.gsub!(/^['"]|['"]$/, '') #L.debug args if !@domain (scout.[scout.uri.host] ||= {})[@name] = self else @name, = args[0] case when Array; @value, @path, @domain = when Hash; @value, @path, @domain = .value, .path, .domain else @value = args[1].to_s end end @path ||= // @domain ||= // @string = "#{@name}=#{@value}; " end |
Instance Method Details
#inspect ⇒ Object
45 |
# File 'lib/rhack/cookie.rb', line 45 def inspect; @value.inspect end |
#to_s ⇒ Object
44 |
# File 'lib/rhack/cookie.rb', line 44 def to_s; @value end |
#use(str, uri) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/rhack/cookie.rb', line 36 def use(str, uri) if !@expires or @expires > Time.now str << @string if uri.path[@path] and !uri.root || uri.host[@domain] else :expired end end |