class Epuber::Compiler::FileTypes::AbstractFile

Attributes

compilation_context[RW]

@return [Epuber::Compiler::CompilationContext] non-nil value only during process() method

destination_path[RW]

@return [String] relative destination path

final_destination_path[RW]

@return [String] final absolute destination path calculated by FileResolver

group[RW]

@return [Symbol] group of this file (:text, :image, :font, …), see Epuber::Compiler::FileFinder::GROUP_EXTENSIONS

path_type[RW]

@return [Symbol] type of path, one of :spine, :manifest, :package

pkg_destination_path[RW]

@return [String] final relative destination path from root of the package calculated by FileResolver

properties[RW]

@return [Set<Symbol>] list of properties

Public Class Methods

file_copy!(source_path, dest_path) click to toggle source

@param [String] source_path @param [String] dest_path

@return nil

# File lib/epuber/compiler/file_types/abstract_file.rb, line 56
def self.file_copy!(source_path, dest_path)
  FileUtils.mkdir_p(File.dirname(dest_path))

  FileUtils.cp(source_path, dest_path)
end
write_to_file(content, to_path) click to toggle source

@param [String | to_s] content anything, that can be converted to string and should be written to file @param [String] to_path destination path

@return nil

# File lib/epuber/compiler/file_types/abstract_file.rb, line 78
def self.write_to_file(content, to_path)
  return unless write_to_file?(content, to_path)

  write_to_file!(content, to_path)
end
write_to_file!(content, to_path) click to toggle source

@param [String | to_s] content anything, that can be converted to string and should be written to file @param [String] to_path destination path

@return nil

# File lib/epuber/compiler/file_types/abstract_file.rb, line 89
def self.write_to_file!(content, to_path)
  FileUtils.mkdir_p(File.dirname(to_path))

  File.open(to_path, 'w') do |file_handle|
    file_handle.write(content)
  end
end
write_to_file?(content, to_path) click to toggle source

@param [String | to_s] content anything, that can be converted to string and should be written to file @param [String] to_path destination path

@return nil

# File lib/epuber/compiler/file_types/abstract_file.rb, line 67
def self.write_to_file?(content, to_path)
  return true unless File.exists?(to_path)

  File.read(to_path) != content.to_s
end

Public Instance Methods

==(other) click to toggle source
# File lib/epuber/compiler/file_types/abstract_file.rb, line 44
def ==(other)
  self.class == other.class && final_destination_path == other.final_destination_path
end