Class: Pitle::FileNameOperator

Inherits:
Object
  • Object
show all
Defined in:
lib/pitle.rb

Overview

Your code goes hereā€¦

Instance Method Summary collapse

Constructor Details

#initialize(filenames, extensions) ⇒ FileNameOperator

Returns a new instance of FileNameOperator.



11
12
13
14
# File 'lib/pitle.rb', line 11

def initialize(filenames, extensions)
  @filenames = filenames
  @extensions = extensions
end

Instance Method Details

#collect_duplicate_filesObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pitle.rb', line 16

def collect_duplicate_files()
  formatted_files = @filenames.each.map { |x| Util.divide_extension(x, @extensions) }

  res = {}
  formatted_files.each do |book|
    name, ext = book
    if res.key?(name) then
      res[name].append(ext)
    else
      res[name] = [ext]
    end
  end

  return res
end

#pick_filesObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pitle.rb', line 32

def pick_files()
  collected_files = collect_duplicate_files()

  res = []
  collected_files.each do |k, v|
    @extensions.each do |e|
      unless v.index(e).nil?
        res.append("#{k}.#{v[v.index(e)]}")
        break
      end
    end
  end

  return res
end