Class: CookieJar::Jar
- Inherits:
-
Object
- Object
- CookieJar::Jar
- Defined in:
- lib/nerdz/http.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_ns(string) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/nerdz/http.rb', line 29 def self.from_ns(string) jar = self.new string.each_line {|l| if l =~ (/^((?:^[^^]+))\s+(TRUE|FALSE)\s+(\S+)\s+(TRUE|FALSE)\s+(\d+)\s+(\S+)\s+(\S+)\s*$/) jar. Cookie.new(domain: $1, path: $3, secure: $4 == 'TRUE' ? true : false, expires_at: Time.at($5.to_i), name: $6, value: $7) end } jar end |
.load_ns(file) ⇒ Object
25 26 27 |
# File 'lib/nerdz/http.rb', line 25 def self.load_ns(file) self.from_ns(File.read(file)) end |
Instance Method Details
#[](name) ⇒ Object
58 59 60 61 62 |
# File 'lib/nerdz/http.rb', line 58 def [](name) self.('http://www.megaupload.com/').select {|| .name == name }.first end |
#save_ns(file) ⇒ Object
52 53 54 55 56 |
# File 'lib/nerdz/http.rb', line 52 def save_ns(file) File.open(file, 'w') {|f| f.write(self.to_ns) } end |
#to_ns ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/nerdz/http.rb', line 42 def to_ns "# Netscape HTTP Cookie File\n" + "# http://curl.haxx.se/rfc/cookie_spec.html\n" + "# This file was generated by nerdz! Edit at your own risk.\n\n" + to_a.map {|| "#{.domain}\t#{.domain[0] == ?. ? 'TRUE' : 'FALSE'}\t#{.path} #{.secure ? 'TRUE' : 'FALSE'}"+ "\t#{.expires_at.to_i}\t#{.name}\t#{.value}\n" if !.session? }.compact.join end |