filenames_set 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/filenames_set.rb +22 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 917b7fda28b5adfbeb3df12eb4a707a86665af48186d88998d9fa5229077b2ec
|
4
|
+
data.tar.gz: ac594a71f34a3bbb70078cf2685b78988717fd31162d95d2f165e26ce13d88bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: db6c919744874341d7a187da5ece61f0855a755bdb7e51dee342ccd01a3a33c6070545799d96a249766c430269c2cddc9a57975eab3623f3ca4971bed6c5d86e
|
7
|
+
data.tar.gz: a65ac26a427060337df8a930e1703ae13928341ff5c67b5b361e410aa0a928b8aa5f1f2e5ab802a8a7e59bdf6f5fb2a9d6e70594bf3e118d45c758fe7c032806
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "set"
|
4
|
+
|
5
|
+
class FilenamesSet
|
6
|
+
def initialize
|
7
|
+
@set = Set.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def <<(filename)
|
11
|
+
counter = 1
|
12
|
+
counter += 1 until @set.add? sequential_filename(filename, counter)
|
13
|
+
sequential_filename(filename, counter)
|
14
|
+
end
|
15
|
+
|
16
|
+
def sequential_filename(filename, counter)
|
17
|
+
base = File.basename(filename, ".*")
|
18
|
+
suffix = "-#{counter}" if counter > 1
|
19
|
+
extension_with_delimiter = File.extname(filename)
|
20
|
+
[base, suffix, extension_with_delimiter].join
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: filenames_set
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergey Burtsev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-07-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Very simple class to ensure that filenames are unique. If you are generating
|
14
|
+
files into directory or adding files to zip archive, you probably want to avoid
|
15
|
+
filenames collistion, when one file can overwrite another one with the same name.
|
16
|
+
If filename is duplicated returns modified filename incremented sequentially.
|
17
|
+
email:
|
18
|
+
- sergey@burtsev.com
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- lib/filenames_set.rb
|
24
|
+
homepage: https://github.com/SergeyBurtsev/filenames_set
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubygems_version: 3.1.6
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: Ruby set for unique filenames
|
47
|
+
test_files: []
|