class Polites::File
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.
Public Class Methods
@param [String, to_path] path path the file to read.
# File lib/polites/file.rb, line 20 def initialize(path) @path = Pathname(path) end
@param [String, to_path] path path the file to read.
# File lib/polites/file.rb, line 11 def self.open(path) file = new(path) file.open yield file ensure file.close end
Public Instance Methods
Close the source file.
@return [Polites::File]
# File lib/polites/file.rb, line 37 def close @zip_file&.close self end
Read the XML contents of the file.
@return [String] the XML contents of the file.
# File lib/polites/file.rb, line 45 def content @zip_file.glob('**/Content.xml').first.get_input_stream.read end
Extract file `subpath` from the source zip file to a given `dest` on disk.
@param [String] subpath @param [String] dest @return [Zip::Entry]
# File lib/polites/file.rb, line 63 def extract_to(subpath, dest) @zip_file.extract(subpath, dest) end
Get a zip entry for a media file with a particular fingerprint substring in its filename.
@param [String] fingerprint @return [Zip::Entry, nil]
# File lib/polites/file.rb, line 54 def media(fingerprint) @zip_file.glob("**/Media/*#{fingerprint}*").first end
Open the source file for reading.
This needs to be called before other operations can be used.
@return [Polites::File]
# File lib/polites/file.rb, line 29 def open @zip_file = Zip::File.open(@path.open) self end