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

new(path) click to toggle source

@param [String, to_path] path path the file to read.

# File lib/polites/file.rb, line 20
def initialize(path)
  @path = Pathname(path)
end
open(path) { |file| ... } click to toggle source

@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() click to toggle source

Close the source file.

@return [Polites::File]

# File lib/polites/file.rb, line 37
def close
  @zip_file&.close
  self
end
content() click to toggle source

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_to(subpath, dest) click to toggle source

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
media(fingerprint) click to toggle source

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() click to toggle source

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