Class: Tankobon::StagedDirectory
- Inherits:
-
Object
- Object
- Tankobon::StagedDirectory
show all
- Defined in:
- lib/tankobon/stageddirectory.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of StagedDirectory.
5
6
7
|
# File 'lib/tankobon/stageddirectory.rb', line 5
def initialize(stage)
@stage = Pathname.new(stage)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/tankobon/stageddirectory.rb', line 54
def method_missing(name, *args, &block)
if name =~ /^rename_(\w+)$/
rename($1.to_sym, &block)
elsif
super
end
end
|
Instance Attribute Details
#stage ⇒ Object
Returns the value of attribute stage.
3
4
5
|
# File 'lib/tankobon/stageddirectory.rb', line 3
def stage
@stage
end
|
Instance Method Details
#all ⇒ Object
35
36
37
|
# File 'lib/tankobon/stageddirectory.rb', line 35
def all
join_stage stage_glob(File.join("**", "*")).sort.reverse
end
|
#all_in_root ⇒ Object
44
45
46
|
# File 'lib/tankobon/stageddirectory.rb', line 44
def all_in_root
join_stage stage_glob("*").sort
end
|
#clean ⇒ Object
28
29
30
31
32
33
|
# File 'lib/tankobon/stageddirectory.rb', line 28
def clean
all_in_root.each do |file|
FileUtils.rm_r(file) unless File.image?(file)
end
self
end
|
#convert_images(&conversion) ⇒ Object
48
49
50
51
52
|
# File 'lib/tankobon/stageddirectory.rb', line 48
def convert_images(&conversion)
images.each do |file|
yield(file) if block_given?
end
end
|
#images ⇒ Object
39
40
41
42
|
# File 'lib/tankobon/stageddirectory.rb', line 39
def images
images_wildcard = "*.{#{File.image_extensions.join(",")}}"
join_stage stage_glob(File.join("**", images_wildcard)).sort
end
|
#mv_images_to(directory) ⇒ Object
16
17
18
19
20
21
|
# File 'lib/tankobon/stageddirectory.rb', line 16
def mv_images_to(directory)
images.each do |file|
FileUtils.mv(file, Pathname.new(directory) + File.basename(file))
end
self
end
|
#mv_images_to_root ⇒ Object
23
24
25
26
|
# File 'lib/tankobon/stageddirectory.rb', line 23
def mv_images_to_root
mv_images_to stage
self
end
|
#rename(what, &block) ⇒ Object
9
10
11
12
13
14
|
# File 'lib/tankobon/stageddirectory.rb', line 9
def rename(what, &block)
send(what).each do |file|
File.xform(file, &block)
end
self
end
|