Class: Epuber::Compiler::FileTypes::AbstractFile
- Inherits:
-
Object
- Object
- Epuber::Compiler::FileTypes::AbstractFile
- Defined in:
- lib/epuber/compiler/file_types/abstract_file.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#compilation_context ⇒ Epuber::Compiler::CompilationContext
Non-nil value only during #process() method.
-
#destination_path ⇒ String
Relative destination path.
-
#final_destination_path ⇒ String
Final absolute destination path calculated by FileResolver.
-
#group ⇒ Symbol
Group of this file (:text, :image, :font, …), see Epuber::Compiler::FileFinder::GROUP_EXTENSIONS.
-
#path_type ⇒ Symbol
Type of path, one of :spine, :manifest, :package.
-
#pkg_destination_path ⇒ String
Final relative destination path from root of the package calculated by FileResolver.
-
#properties ⇒ Set<Symbol>
List of properties.
Class Method Summary collapse
-
.file_copy!(source_path, dest_path) ⇒ Object
Nil.
-
.write_to_file(content, to_path) ⇒ Object
Nil.
-
.write_to_file!(content, to_path) ⇒ Object
Nil.
-
.write_to_file?(content, to_path) ⇒ Boolean
Nil.
Instance Method Summary collapse
Instance Attribute Details
#compilation_context ⇒ Epuber::Compiler::CompilationContext
Returns non-nil value only during #process() method.
42 43 44 |
# File 'lib/epuber/compiler/file_types/abstract_file.rb', line 42 def compilation_context @compilation_context end |
#destination_path ⇒ String
Returns 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_path ⇒ String
Returns 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 |
#group ⇒ Symbol
Returns 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_type ⇒ Symbol
Returns 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_path ⇒ String
Returns 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 |
#properties ⇒ Set<Symbol>
Returns 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.
56 57 58 59 60 |
# 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) ⇒ Object
Returns nil.
78 79 80 81 82 |
# 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) ⇒ Object
Returns nil.
89 90 91 92 93 94 95 |
# 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) ⇒ Boolean
Returns nil.
67 68 69 70 71 |
# 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 |
Instance Method Details
#==(other) ⇒ Object
44 45 46 |
# 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 |