Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/tankobon/ext/file.rb

Class Method Summary collapse

Class Method Details

.archive?(file) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/tankobon/ext/file.rb', line 35

def self.archive?(file)
  archive_extensions.include? File.extname(file).tail
end

.archive_extensionsObject



39
40
41
# File 'lib/tankobon/ext/file.rb', line 39

def self.archive_extensions
  ['zip', 'rar', 'cbz', 'cbr']
end

.bubble_mv(root_dir, file) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/tankobon/ext/file.rb', line 8

def self.bubble_mv(root_dir, file)
  return if root_dir.eql? File.dirname(file)
  new_name = "#{File.basename(File.dirname(file))}-#{File.basename(file)}"
  new_full_name = File.join(
          File.dirname(File.dirname(file)),
          new_name)
  File.rename(file, new_full_name)
  self.bubble_mv(root_dir, new_full_name)
end

.image?(file) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/tankobon/ext/file.rb', line 27

def self.image?(file)
  image_extensions.include? File.extname(file).tail
end

.image_extensionsObject



31
32
33
# File 'lib/tankobon/ext/file.rb', line 31

def self.image_extensions
  ['jpg', 'jpeg', 'png', 'gif']
end

.rnbase(file, new_name) ⇒ Object



18
19
20
21
# File 'lib/tankobon/ext/file.rb', line 18

def self.rnbase(file, new_name)
  File.rename(file,
    File.join(File.dirname(file), "#{new_name}#{File.extname(file)}"))
end

.splitbase(file) ⇒ Object



23
24
25
# File 'lib/tankobon/ext/file.rb', line 23

def self.splitbase(file)
  [File.basename(file, ".*"), File.extname(file)]
end

.xform(file_name, &block) ⇒ Object



2
3
4
5
6
# File 'lib/tankobon/ext/file.rb', line 2

def self.xform(file_name, &block)
  base_name, _ = File.splitbase(file_name)
  block = Proc.new {|name| name} if not block_given?
  rnbase(file_name, block.call(base_name))
end