zaru 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/zaru.rb +6 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7a8f1cb70a791e4ae4cb5412b02718bd8104fa7b174248308f1c96baf7bfc381
|
4
|
+
data.tar.gz: 41def52efe381ff45bb7809298ecb11a7d7a4e87299e25b9842f1307c8e564fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42241d17943c01936926d45a29a65804c8863428ec508a6567a358629986952dbf96c0415ac427bafa34ad5cdb5f9bb487cedc2d3fe375f68e2b9af4898c791f
|
7
|
+
data.tar.gz: 4f519b07268eebe240efc4d25fbbae19d2980ea38149358c354f7c5fb1d82d62f8f166f8da3ac1afff0d88301b4abdf57004a2c3061e3dde57a166b503380675
|
data/lib/zaru.rb
CHANGED
@@ -10,6 +10,7 @@ class Zaru
|
|
10
10
|
FALLBACK_FILENAME = 'file'
|
11
11
|
|
12
12
|
def initialize(filename, options = {})
|
13
|
+
@fallback = options[:fallback] || FALLBACK_FILENAME
|
13
14
|
@padding = options[:padding] || 0
|
14
15
|
@raw = filename.to_s.freeze
|
15
16
|
end
|
@@ -50,6 +51,8 @@ class Zaru
|
|
50
51
|
|
51
52
|
private
|
52
53
|
|
54
|
+
attr_reader :fallback
|
55
|
+
|
53
56
|
def filter(filename)
|
54
57
|
filename = filter_windows_reserved_names(filename)
|
55
58
|
filename = filter_blank(filename)
|
@@ -57,15 +60,15 @@ class Zaru
|
|
57
60
|
end
|
58
61
|
|
59
62
|
def filter_windows_reserved_names(filename)
|
60
|
-
WINDOWS_RESERVED_NAMES.include?(filename.upcase) ?
|
63
|
+
WINDOWS_RESERVED_NAMES.include?(filename.upcase) ? fallback : filename
|
61
64
|
end
|
62
65
|
|
63
66
|
def filter_blank(filename)
|
64
|
-
filename.empty??
|
67
|
+
filename.empty?? fallback : filename
|
65
68
|
end
|
66
69
|
|
67
70
|
def filter_dot(filename)
|
68
|
-
filename.start_with?('.')? "#{
|
71
|
+
filename.start_with?('.')? "#{fallback}#{filename}" : filename
|
69
72
|
end
|
70
73
|
|
71
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zaru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Fuchs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Zaru takes a given filename (a string) and normalizes, filters and truncates
|
14
14
|
it, so it can be safely used as a filename in modern operating systems. Zaru doesn't
|
@@ -38,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
38
|
version: '0'
|
39
39
|
requirements: []
|
40
40
|
rubyforge_project:
|
41
|
-
rubygems_version: 2.6
|
41
|
+
rubygems_version: 2.7.6
|
42
42
|
signing_key:
|
43
43
|
specification_version: 4
|
44
44
|
summary: Filename sanitization for Ruby
|