Class: WANG::Jar
- Inherits:
-
Object
- Object
- WANG::Jar
- Defined in:
- lib/wang.rb
Instance Method Summary collapse
- #add(c) ⇒ Object
- #consume(raw_cookie, uri = nil) ⇒ Object
- #cookies_for(uri) ⇒ Object
- #has_cookies_for?(uri) ⇒ Boolean
- #include?(c) ⇒ Boolean
- #index(c) ⇒ Object
-
#initialize ⇒ Jar
constructor
A new instance of Jar.
- #load(io) ⇒ Object
- #save(io) ⇒ Object
Constructor Details
#initialize ⇒ Jar
Returns a new instance of Jar.
371 372 373 |
# File 'lib/wang.rb', line 371 def initialize @jar = [] end |
Instance Method Details
#add(c) ⇒ Object
380 381 382 383 384 385 386 387 |
# File 'lib/wang.rb', line 380 def add c i = index(c) if i.nil? @jar << c else @jar[i] = c end end |
#consume(raw_cookie, uri = nil) ⇒ Object
375 376 377 378 |
# File 'lib/wang.rb', line 375 def consume , uri = nil = Cookie.new.parse(, uri) add() end |
#cookies_for(uri) ⇒ Object
393 394 395 396 |
# File 'lib/wang.rb', line 393 def uri @jar -= @jar.select { |c| c.expired? } @jar.select { |c| c.match?(uri) }.map{ |c| "#{c.key}=#{c.value}" }.join("; ") end |
#has_cookies_for?(uri) ⇒ Boolean
389 390 391 |
# File 'lib/wang.rb', line 389 def uri not (uri).empty? end |
#include?(c) ⇒ Boolean
406 407 408 |
# File 'lib/wang.rb', line 406 def include? c not index(c).nil? end |
#index(c) ⇒ Object
398 399 400 401 402 403 404 |
# File 'lib/wang.rb', line 398 def index c @jar.each do || return @jar.index() if .same? c end nil end |
#load(io) ⇒ Object
415 416 417 418 419 420 421 |
# File 'lib/wang.rb', line 415 def load io saved_jar = YAML::load(io) saved_jar.each do |c| add(c) end end |
#save(io) ⇒ Object
410 411 412 413 |
# File 'lib/wang.rb', line 410 def save io io << @jar.to_yaml io.close end |