Class: Epuber::Compiler::FileTypes::AbstractFile

Inherits:
Object
  • Object
show all
Defined in:
lib/epuber/compiler/file_types/abstract_file.rb

Direct Known Subclasses

GeneratedFile, SourceFile

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#destination_pathString

Returns relative destination path.

Returns:

  • (String)

    relative destination path



11
12
13
# File 'lib/epuber/compiler/file_types/abstract_file.rb', line 11

def destination_path
  @destination_path
end

#final_destination_pathString

Returns final absolute destination path calculated by FileResolver.

Returns:

  • (String)

    final absolute destination path calculated by FileResolver



34
35
36
# File 'lib/epuber/compiler/file_types/abstract_file.rb', line 34

def final_destination_path
  @final_destination_path
end

#groupSymbol

Returns group of this file (:text, :image, :font, …), see Epuber::Compiler::FileFinder::GROUP_EXTENSIONS.

Returns:

  • (Symbol)

    group of this file (:text, :image, :font, …), see Epuber::Compiler::FileFinder::GROUP_EXTENSIONS



15
16
17
# File 'lib/epuber/compiler/file_types/abstract_file.rb', line 15

def group
  @group
end

#path_typeSymbol

Returns type of path, one of :spine, :manifest, :package.

Returns:

  • (Symbol)

    type of path, one of :spine, :manifest, :package



38
39
40
# File 'lib/epuber/compiler/file_types/abstract_file.rb', line 38

def path_type
  @path_type
end

#pkg_destination_pathString

Returns final relative destination path from root of the package calculated by FileResolver.

Returns:

  • (String)

    final relative destination path from root of the package calculated by FileResolver



30
31
32
# File 'lib/epuber/compiler/file_types/abstract_file.rb', line 30

def pkg_destination_path
  @pkg_destination_path
end

#propertiesSet<Symbol>

Returns list of properties.

Returns:

  • (Set<Symbol>)

    list of properties



19
20
21
# File 'lib/epuber/compiler/file_types/abstract_file.rb', line 19

def properties
  @properties
end

Class Method Details

.file_copy(source_path, dest_path) ⇒ Object

Returns nil.

Parameters:

  • source_path (String)
  • dest_path (String)

Returns:

  • nil



65
66
67
68
69
# File 'lib/epuber/compiler/file_types/abstract_file.rb', line 65

def self.file_copy(source_path, dest_path)
  return unless file_copy?(source_path, dest_path)

  file_copy!(source_path, dest_path)
end

.file_copy!(source_path, dest_path) ⇒ Object

Returns nil.

Parameters:

  • source_path (String)
  • dest_path (String)

Returns:

  • nil



76
77
78
79
80
# File 'lib/epuber/compiler/file_types/abstract_file.rb', line 76

def self.file_copy!(source_path, dest_path)
  FileUtils.mkdir_p(File.dirname(dest_path))

  FileUtils.cp(source_path, dest_path)
end

.file_copy?(source_path, dest_path) ⇒ Bool

Parameters:

  • source_path (String)
  • dest_path (String)

Returns:

  • (Bool)


53
54
55
56
57
58
# File 'lib/epuber/compiler/file_types/abstract_file.rb', line 53

def self.file_copy?(source_path, dest_path)
  return false if FileUtils.uptodate?(dest_path, [source_path])
  return false if File.exists?(dest_path) && FileUtils.compare_file(dest_path, source_path)

  true
end

.write_to_file(content, to_path) ⇒ Object

Returns nil.

Parameters:

  • content (String | #to_s)

    anything, that can be converted to string and should be written to file

  • to_path (String)

    destination path

Returns:

  • nil



98
99
100
101
102
# File 'lib/epuber/compiler/file_types/abstract_file.rb', line 98

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) ⇒ Object

Returns nil.

Parameters:

  • content (String | #to_s)

    anything, that can be converted to string and should be written to file

  • to_path (String)

    destination path

Returns:

  • nil



109
110
111
112
113
114
115
# File 'lib/epuber/compiler/file_types/abstract_file.rb', line 109

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) ⇒ Boolean

Returns nil.

Parameters:

  • content (String | #to_s)

    anything, that can be converted to string and should be written to file

  • to_path (String)

    destination path

Returns:

  • (Boolean)

    nil



87
88
89
90
91
# File 'lib/epuber/compiler/file_types/abstract_file.rb', line 87

def self.write_to_file?(content, to_path)
  return true unless File.exists?(to_path)

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

Instance Method Details

#==(other) ⇒ Object



41
42
43
# File 'lib/epuber/compiler/file_types/abstract_file.rb', line 41

def ==(other)
  self.class == other.class && final_destination_path == other.final_destination_path
end