aboutsummaryrefslogtreecommitdiffstats
path: root/app/services/file_service.rb
blob: efccbe24f433f73d54cc6efd7f0a16474bde30e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module FileService extend self

  def unique_filename( path, enum_with: with_ints )
    file_names = enum_with.map( &file_name_maker(path) )
    file_names
      .drop_while( &File.method(:exists?) )
      .next
  end

  def with_ints(format='%d')
    (0..Float::INFINITY)
      .lazy
      .map{ |n| format % n }
  end
  

  private

  def file_name_maker path
    ->(n){ [path, n].join('_') }
  end

end