Module: Renchin::FileProcessor

Included in:
CLI, Client
Defined in:
lib/renchin/file_processor.rb

Instance Method Summary collapse

Instance Method Details

#delete_directory(image_directory_path, expr) ⇒ Object

delete all files in directory



12
13
14
15
16
17
18
19
# File 'lib/renchin/file_processor.rb', line 12

def delete_directory(image_directory_path,expr)
  if exists?(image_directory_path)
    Dir::foreach(image_directory_path) do |file|
      File.delete(image_directory_path + '/' + file) if (/#{expr}$/ =~ file)
    end
    Dir::rmdir(image_directory_path)
  end
end

#exists?(filename) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/renchin/file_processor.rb', line 21

def exists?(filename)
  File.exist?(filename)
end

#image_directory(method_name) ⇒ Object

create temporary directory for frame images



5
6
7
8
9
# File 'lib/renchin/file_processor.rb', line 5

def image_directory(method_name)
  timestamp_image_dir = "/tmp/renchin_#{method_name}_#{Time.now.to_i}"
  Dir::mkdir(timestamp_image_dir,0777)
  timestamp_image_dir
end

#init_file(filename) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/renchin/file_processor.rb', line 25

def init_file(filename)
  unless File.exist?(filename)
    dir = File.dirname(filename)
    unless File.exist?(dir)
      FileUtils.mkdir_p(dir)
    end
  end
  true
end