Class: Sicily::Util::FileUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/sicily/util/file_util.rb

Class Method Summary collapse

Class Method Details

.eval_dest_path(src_path, dest_path) ⇒ Object



16
17
18
19
# File 'lib/sicily/util/file_util.rb', line 16

def self.eval_dest_path(src_path, dest_path)
  time = extract_time(src_path)
  time.strftime(dest_path)
end

.extract_time(path) ⇒ Object



21
22
23
24
# File 'lib/sicily/util/file_util.rb', line 21

def self.extract_time(path)
  exif_time = jpeg?(path) && ExifUtil.extract_time_from_jpeg(path)
  exif_time || extract_time_from_file_stat(path)
end

.extract_time_from_file_stat(path) ⇒ Object



30
31
32
33
34
# File 'lib/sicily/util/file_util.rb', line 30

def self.extract_time_from_file_stat(path)
  File.birthtime(path)
rescue NotImplementedError
  File.mtime(path)
end

.jpeg?(path) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/sicily/util/file_util.rb', line 26

def self.jpeg?(path)
  %w[.jpg .jpeg].include? File.extname(path).downcase
end

.related?(maybe_parent_path, maybe_child_path) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
# File 'lib/sicily/util/file_util.rb', line 9

def self.related?(maybe_parent_path, maybe_child_path)
  expanded_parent_path = File.expand_path(maybe_parent_path)
  expanded_child_path = File.expand_path(maybe_child_path)
  parent_path_expr = File.join(expanded_parent_path, '**')
  Pathname.new(expanded_child_path).fnmatch? parent_path_expr
end