Class: Depix::Editor
- Inherits:
-
Delegator
- Object
- Delegator
- Depix::Editor
- Defined in:
- lib/depix/editor.rb
Overview
Used to edit DPX headers. Create an Editor object and pass the path to the file to it. Change the headers variable to contain the edited DPX headers and call commit!. Note that the DPX header will be overwritten in place - if you want to save another version you need to manage it yourself.
dpx = Depix::Editor.new("/RAID/scans/1374470_adjusted.dpx")
dpx.file.copyright = "Copyleft"
dpx.file.reserve = "FileReserve"
dpx.orientation.reserve = "OrientReserve"
dpx.orientation.device = "Chainik"
dpx.orientation.serial = "43"
dpx.film.reserve = "FilmRezerve"
dpx.file.project = "Mastermind"
dpx.commit! # will write out the headers
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Stores the path to file.
Instance Method Summary collapse
- #__getobj__ ⇒ Object
-
#commit! ⇒ Object
Save the headers to file at path, overwriting the old ones.
-
#copy_from(another, *fields_to_copy) ⇒ Object
Copy headers from another DPX object.
-
#headers ⇒ Object
DEPRECATED.
-
#initialize(file_path) ⇒ Editor
constructor
Create a new editor for the file at path.
Constructor Details
Instance Attribute Details
#path ⇒ Object (readonly)
Stores the path to file
21 22 23 |
# File 'lib/depix/editor.rb', line 21 def path @path end |
Instance Method Details
#__getobj__ ⇒ Object
56 57 58 |
# File 'lib/depix/editor.rb', line 56 def __getobj__ @dpx # return object we are delegating to, required end |
#commit! ⇒ Object
Save the headers to file at path, overwriting the old ones
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/depix/editor.rb', line 39 def commit! raise "No headers" unless @dpx raise "Cannot pack LE headers yet" if @dpx.le? packed = @dpx.class.pack(@dpx) # Use in-place writing into DPX file (this is what + does) File.open(@path, 'rb+') do | f | f.seek(0, IO::SEEK_SET); f.write(packed) end end |
#copy_from(another, *fields_to_copy) ⇒ Object
Copy headers from another DPX object
30 31 32 33 34 35 36 |
# File 'lib/depix/editor.rb', line 30 def copy_from(another, *fields_to_copy) if fields_to_copy.empty? @dpx = another.dup else fields_to_copy.each{|f| @dpx[f] = another[f] } end end |
#headers ⇒ Object
DEPRECATED
51 52 53 54 |
# File 'lib/depix/editor.rb', line 51 def headers STDERR.puts "Depix::Editor#headers is deprecated, use the Editor itself instead" self end |