Class: Pinch
- Inherits:
-
Object
- Object
- Pinch
- Defined in:
- lib/pinch.rb
Overview
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
-
.content_length(url) ⇒ Fixnum
Retrieve the size of the ZIP file.
-
.file_list(url) ⇒ Array
List of files inside the zip file.
-
.get(url, file_name) ⇒ String
Retrieve a file from inside a zip file, over the network!.
Instance Method Summary collapse
- #content_length ⇒ Object
- #file_list ⇒ Object
- #get(file_name) ⇒ Object
-
#initialize(url) ⇒ Pinch
constructor
Initializes a new Pinch object.
Constructor Details
#initialize(url) ⇒ Pinch
Note:
You might want to use Pinch.get instead.
Initializes a new Pinch object
58 59 60 61 |
# File 'lib/pinch.rb', line 58 def initialize(url) @uri = URI.parse(url) @files = {} end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
10 11 12 |
# File 'lib/pinch.rb', line 10 def uri @uri end |
Class Method Details
.content_length(url) ⇒ Fixnum
Retrieve the size of the ZIP file
48 49 50 |
# File 'lib/pinch.rb', line 48 def self.content_length(url) new(url).content_length end |
.file_list(url) ⇒ Array
List of files inside the zip file
35 36 37 |
# File 'lib/pinch.rb', line 35 def self.file_list(url) new(url).file_list end |
.get(url, file_name) ⇒ String
Retrieve a file from inside a zip file, over the network!
22 23 24 |
# File 'lib/pinch.rb', line 22 def self.get(url, file_name) new(url).get(file_name) end |
Instance Method Details
#content_length ⇒ Object
Note:
You might want to use Pinch.content_length instead
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/pinch.rb', line 84 def content_length @content_length ||= begin response = prepared_connection.start { |http| http.head(@uri.path) } # Raise exception if the response code isn’t in the 2xx range response.error! unless response.kind_of?(Net::HTTPSuccess) response['Content-Length'].to_i end end |
#file_list ⇒ Object
Note:
You might want to use Pinch.file_list instead.
66 67 68 |
# File 'lib/pinch.rb', line 66 def file_list file_headers.keys end |
#get(file_name) ⇒ Object
Note:
You might want to use Pinch.get instead
77 78 79 |
# File 'lib/pinch.rb', line 77 def get(file_name) local_file(file_name) end |