string-obfuscator 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/string-obfuscator/version.rb +1 -1
- data/lib/string-obfuscator.rb +4 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3019e84dc394179efd0899ffe984317fea42ea09
|
4
|
+
data.tar.gz: 43a7ff3c716712d26cfda5738e23e79de48cb67c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 026ea77e79b7f389feb1f45e11c3d11f51f334c33fb23fd66164381a586ffc90f4e7aa13f2e36494c548e5cee02d8e5946e4e78ec08a83df7339cd928db96548
|
7
|
+
data.tar.gz: 9a4ca58922e983212173cbb1cd5b274a92c635ff05eea0f5ab2fab44ca343ad46cc4ff93c7a8f8c57755b940d37c0cedfb6bae789ccb8123c09cfe8dc4656c53
|
data/README.md
CHANGED
@@ -23,6 +23,13 @@ StringObfuscator.obfuscate("Hello? It's me, Danilo", percent: 20, obfuscation_va
|
|
23
23
|
=> "[obfuscated]? It's me, Danilo"
|
24
24
|
```
|
25
25
|
|
26
|
+
Example usage - min obfuscated length:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
StringObfuscator.obfuscate("Hello world", percent: 25, min_obfuscated_length: 8)
|
30
|
+
=> "********rld"
|
31
|
+
```
|
32
|
+
|
26
33
|
## Installation
|
27
34
|
|
28
35
|
Add this line to your application's Gemfile:
|
data/lib/string-obfuscator.rb
CHANGED
@@ -2,7 +2,7 @@ require "string-obfuscator/version"
|
|
2
2
|
require "bigdecimal"
|
3
3
|
|
4
4
|
module StringObfuscator
|
5
|
-
def self.obfuscate(value, percent: nil, length: nil, from: :left, max_unobfuscated_length: nil, obfuscation_character: "*", obfuscation_value: nil)
|
5
|
+
def self.obfuscate(value, percent: nil, length: nil, from: :left, max_unobfuscated_length: nil, min_obfuscated_length: nil, obfuscation_character: "*", obfuscation_value: nil)
|
6
6
|
raise ArgumentError, "must specify percent or length to obfuscate by" if percent.nil? && length.nil?
|
7
7
|
raise ArgumentError, "percent must be between 0 - 100" if !percent.nil? && (percent > 100 || percent < 0)
|
8
8
|
raise ArgumentError, "length must be > 0" if !length.nil? && length < 0
|
@@ -12,8 +12,10 @@ module StringObfuscator
|
|
12
12
|
percent = BigDecimal.new(percent.to_s)
|
13
13
|
obfuscated_length = (value.length * (percent / 100)).ceil
|
14
14
|
else
|
15
|
-
obfuscated_length =
|
15
|
+
obfuscated_length = length
|
16
16
|
end
|
17
|
+
obfuscated_length = [obfuscated_length, min_obfuscated_length].max if min_obfuscated_length
|
18
|
+
obfuscated_length = [obfuscated_length, value.length].min
|
17
19
|
visible_length = value.length - obfuscated_length
|
18
20
|
|
19
21
|
# If `max_unobfuscated_length` is set, ensure that we don't show more than that.
|