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.
377 378 379 |
# File 'lib/wang.rb', line 377 def initialize @jar = [] end |
Instance Method Details
#add(c) ⇒ Object
386 387 388 389 390 391 392 393 |
# File 'lib/wang.rb', line 386 def add c i = index(c) if i.nil? @jar << c else @jar[i] = c end end |
#consume(raw_cookie, uri = nil) ⇒ Object
381 382 383 384 |
# File 'lib/wang.rb', line 381 def consume , uri = nil = Cookie.new.parse(, uri) add() end |
#cookies_for(uri) ⇒ Object
399 400 401 402 |
# File 'lib/wang.rb', line 399 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
395 396 397 |
# File 'lib/wang.rb', line 395 def uri not (uri).empty? end |
#include?(c) ⇒ Boolean
412 413 414 |
# File 'lib/wang.rb', line 412 def include? c not index(c).nil? end |
#index(c) ⇒ Object
404 405 406 407 408 409 410 |
# File 'lib/wang.rb', line 404 def index c @jar.each do || return @jar.index() if .same? c end nil end |
#load(io) ⇒ Object
421 422 423 424 425 426 427 |
# File 'lib/wang.rb', line 421 def load io saved_jar = YAML::load(io) saved_jar.each do |c| add(c) end end |
#save(io) ⇒ Object
416 417 418 419 |
# File 'lib/wang.rb', line 416 def save io io << @jar.to_yaml io.close end |