Class: Polites::File
- Inherits:
-
Object
- Object
- Polites::File
- Defined in:
- lib/polites/file.rb
Overview
A Polites::File
represents a file saved to disk by Polites with a .ulyz
extension. This is a zip file containing the text contents in XML format
along with all assets.
Class Method Summary collapse
Instance Method Summary collapse
-
#close ⇒ Polites::File
Close the source file.
-
#content ⇒ String
Read the XML contents of the file.
-
#extract_to(subpath, dest) ⇒ Zip::Entry
Extract file
subpath
from the source zip file to a givendest
on disk. -
#initialize(path) ⇒ File
constructor
A new instance of File.
-
#media(fingerprint) ⇒ Zip::Entry?
Get a zip entry for a media file with a particular fingerprint substring in its filename.
-
#open ⇒ Polites::File
Open the source file for reading.
Constructor Details
#initialize(path) ⇒ File
Returns a new instance of File.
20 21 22 |
# File 'lib/polites/file.rb', line 20 def initialize(path) @path = Pathname(path) end |
Class Method Details
.open(path) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/polites/file.rb', line 11 def self.open(path) file = new(path) file.open yield file ensure file.close end |
Instance Method Details
#close ⇒ Polites::File
Close the source file.
37 38 39 40 |
# File 'lib/polites/file.rb', line 37 def close @zip_file&.close self end |
#content ⇒ String
Read the XML contents of the file.
45 46 47 |
# File 'lib/polites/file.rb', line 45 def content @zip_file.glob('**/Content.xml').first.get_input_stream.read end |
#extract_to(subpath, dest) ⇒ Zip::Entry
Extract file subpath
from the source zip file to a given dest
on disk.
63 64 65 |
# File 'lib/polites/file.rb', line 63 def extract_to(subpath, dest) @zip_file.extract(subpath, dest) end |
#media(fingerprint) ⇒ Zip::Entry?
Get a zip entry for a media file with a particular fingerprint substring in its filename.
54 55 56 |
# File 'lib/polites/file.rb', line 54 def media(fingerprint) @zip_file.glob("**/Media/*#{fingerprint}*").first end |
#open ⇒ Polites::File
Open the source file for reading.
This needs to be called before other operations can be used.
29 30 31 32 |
# File 'lib/polites/file.rb', line 29 def open @zip_file = Zip::File.open(@path.open) self end |