Class: Depix::Editor

Inherits:
Delegator
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Editor

Create a new editor for the file at path



24
25
26
27
# File 'lib/depix/editor.rb', line 24

def initialize(file_path)
  @path = file_path
  @dpx = Depix.from_file(@path)
end

Instance Attribute Details

#pathObject (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



50
51
52
# File 'lib/depix/editor.rb', line 50

def __getobj__
  @dpx # return object we are delegating to, required
end

#commit!Object

Save the headers to file at path, overwriting the old ones



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/depix/editor.rb', line 30

def commit!
  raise "No headers" unless @dpx
  raise "Cannot pack LE headers yet" if @dpx.le?
  packed = @dpx.class.pack(@dpx)
  
  # Validate that we can unpack first - what if something went wrong?
  Depix::Reader.new.parse(packed, false)
  
  # 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

#headersObject

DEPRECATED



45
46
47
48
# File 'lib/depix/editor.rb', line 45

def headers
  STDERR.puts "Depix::Editor#headers is deprecated, use the Editor itself instead"
  self
end