Class: Copy

Inherits:
Object
  • Object
show all
Defined in:
lib/imagelib/copy2lib.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, prefix) ⇒ Copy

Returns a new instance of Copy.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/imagelib/copy2lib.rb', line 13

def initialize(filename, prefix)
  @filename = filename
  @prefix = prefix
  @creation_date = File.mtime(filename)
  @target_path = sprintf("%s/%d/%02d/%d-%02d-%02d",
                         OUT_DIR,
                         @creation_date.year,
                         @creation_date.month,
                         @creation_date.year,
                         @creation_date.month,
                         @creation_date.day)
  @target_filename = "#{@target_path}/#{@prefix}#{File.basename(@filename)}"
  @flag_filename = "#{@filename}.#{ENV['LOGNAME']}"
end

Instance Attribute Details

#creation_dateObject (readonly)

Returns the value of attribute creation_date.



12
13
14
# File 'lib/imagelib/copy2lib.rb', line 12

def creation_date
  @creation_date
end

#filenameObject (readonly)

Returns the value of attribute filename.



12
13
14
# File 'lib/imagelib/copy2lib.rb', line 12

def filename
  @filename
end

#prefixObject (readonly)

Returns the value of attribute prefix.



12
13
14
# File 'lib/imagelib/copy2lib.rb', line 12

def prefix
  @prefix
end

#target_pathObject (readonly)

Returns the value of attribute target_path.



12
13
14
# File 'lib/imagelib/copy2lib.rb', line 12

def target_path
  @target_path
end

Instance Method Details

#copyObject



32
33
34
35
36
37
38
39
# File 'lib/imagelib/copy2lib.rb', line 32

def copy
  if (work_to_do?)
    puts "#{@filename} -> #{@target_filename}"
    FileUtils::cp(@filename, @target_filename, :preserve=>true )
    File.open(@flag_filename, 'w') { |file| }
    return @target_filename
  end
end

#prepareObject



28
29
30
# File 'lib/imagelib/copy2lib.rb', line 28

def prepare
  FileUtils::mkdir_p(@target_path)
end

#to_sObject



46
47
48
# File 'lib/imagelib/copy2lib.rb', line 46

def to_s
  return "#{@filename} with #{prefix}"
end

#work_to_do?Boolean

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/imagelib/copy2lib.rb', line 41

def work_to_do?
  return !(File.exists?(@target_filename) or
           File.exists?(@flag_filename))
end