Class: Nrename::Directory

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/nrename/directory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Directory

Returns a new instance of Directory.



14
15
16
17
# File 'lib/nrename/directory.rb', line 14

def initialize(dir)
  @dir = Pathname.new dir
  @counter = Counter.new
end

Instance Attribute Details

#counterObject (readonly)

Returns the value of attribute counter.



12
13
14
# File 'lib/nrename/directory.rb', line 12

def counter
  @counter
end

Instance Method Details

#directoriesObject



19
20
21
# File 'lib/nrename/directory.rb', line 19

def directories
  @dir.children.select &:directory?
end

#filesObject



27
28
29
# File 'lib/nrename/directory.rb', line 27

def files
  options.rename_dirs ? directories : regular_files
end

#max_numberObject



42
43
44
45
46
47
48
# File 'lib/nrename/directory.rb', line 42

def max_number
  if options.renumber
    numbered_files.size
  else
    numbered_files.map(&:number_from_path).max
  end
end

#normalizeObject



50
51
52
53
54
# File 'lib/nrename/directory.rb', line 50

def normalize
  numbered_files.each do |file|
    file.normalize
  end
end

#num_field_lengthObject



38
39
40
# File 'lib/nrename/directory.rb', line 38

def num_field_length
  @num_field_length ||= max_number.to_s.size
end

#numbered_filesObject



31
32
33
34
35
36
# File 'lib/nrename/directory.rb', line 31

def numbered_files
  @numbered_files ||= files.
    select { |file| file.basename.to_s =~ options.pattern }.
    map { |file| NumberedFile.new file, self }.
    sort_by(&:number_from_path)
end

#regular_filesObject



23
24
25
# File 'lib/nrename/directory.rb', line 23

def regular_files
  @dir.children.select &:file?
end