string-obfuscator 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45d57f6fb28115cfafbf6d84ebd8811b01ddbcc5
4
- data.tar.gz: 85256c94d3838aecff703fad0717e06ed7f5a7b3
3
+ metadata.gz: 3019e84dc394179efd0899ffe984317fea42ea09
4
+ data.tar.gz: 43a7ff3c716712d26cfda5738e23e79de48cb67c
5
5
  SHA512:
6
- metadata.gz: 71f3b35b91b17b73f2bd42114d6d1c8968501850e415257b883c365762306c56e7866deb76ea49da534c4e8dfbce9edb01d19f9a0a934dfd6323e106b93228c5
7
- data.tar.gz: a11dd5f8e5ebe76db292728613d2c79a109d2355ed5c2c499d94ecdf5a837d9e0faea919982c10f6aa0e253cbf715669e48d63d296e6095ca9f2c45625cdfb99
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:
@@ -1,3 +1,3 @@
1
1
  module StringObfuscator
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -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 = [value.length, length].min
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.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string-obfuscator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Graham