Class: Copy
- Inherits:
-
Object
- Object
- Copy
- Defined in:
- lib/imagelib/copy2lib.rb
Instance Attribute Summary collapse
-
#creation_date ⇒ Object
readonly
Returns the value of attribute creation_date.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#target_path ⇒ Object
readonly
Returns the value of attribute target_path.
Instance Method Summary collapse
- #copy ⇒ Object
-
#initialize(filename, prefix) ⇒ Copy
constructor
A new instance of Copy.
- #prepare ⇒ Object
- #to_s ⇒ Object
- #work_to_do? ⇒ Boolean
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_date ⇒ Object (readonly)
Returns the value of attribute creation_date.
12 13 14 |
# File 'lib/imagelib/copy2lib.rb', line 12 def creation_date @creation_date end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
12 13 14 |
# File 'lib/imagelib/copy2lib.rb', line 12 def filename @filename end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
12 13 14 |
# File 'lib/imagelib/copy2lib.rb', line 12 def prefix @prefix end |
#target_path ⇒ Object (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
#copy ⇒ Object
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 |
#prepare ⇒ Object
28 29 30 |
# File 'lib/imagelib/copy2lib.rb', line 28 def prepare FileUtils::mkdir_p(@target_path) end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/imagelib/copy2lib.rb', line 46 def to_s return "#{@filename} with #{prefix}" end |
#work_to_do? ⇒ 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 |