sanistring 0.0.1 → 0.0.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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTU3YmYwOWQ4ZWI3Y2M2YWViNGUyODZlOWJkNzY4YzUzY2NkZDFhYQ==
4
+ NzY3OWRmYTc0ZWEwMWRlZjczMjYxZDg1MWVkNzhhMmRiMDc0YjJkYQ==
5
5
  data.tar.gz: !binary |-
6
- NDk1MzZmYzQ1YWJmMDQ1NDkwMjkwYzhjNjY1YzQxYmFhYTlmOWZiYQ==
6
+ Y2U4MWJlODA2ODE4NmZlYzk2ZjVhODBiNTZjMjlkNDNhZTEzYTkzYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjI3OThmOTE5NTg5YWU4MWM2ZDNiYmE0MDY0NzJjOGI2MDU0Y2I1OGNmMzVl
10
- NThiNDJmNjg2ZjNjYzRkMWUzZTc2MzUzYzk2OTJkNjBjYTM5ODE5N2ZhYWU3
11
- ZmJlMjZlNmI1OTFhZDA4NGQ5MjYwOGRlZDRkNGQ4NzJiNzFjZTQ=
9
+ ODM5MGYxMzExN2Q3OGY4NmMxNTc1YjMxNTU0YjA3ZjYzNTc2YTQ0M2MyNjZh
10
+ Y2Q4Njg0ODFjNzM4NmQ1YmYyYTJjNzUyYjQ4NjhkNGRlZTQwZGE2NTJlYTRk
11
+ OTU2NGZiNTA0OTIyMmNmNGFiOGJhMDA4YTA3YjkyNjhlMTE1MzU=
12
12
  data.tar.gz: !binary |-
13
- MWUyN2YzNTYwMDUxNmNmNTZmODFlMDRjZDlkZjdmMzE2NTQ2ZDlmZmZkMmQz
14
- MTgwNDk3MzM3ZTU5ZDEyZTg4MjI2MmI3MzI4ZmIwYmIxZjI0Yjk0YTNjYzY1
15
- ZTg1ZWU3NTZlNWU1NmI0ZGU4NjE5YTdjNmViODU3NzRiMWE5OWM=
13
+ ZGFiOTBlZjJjNTI4OTllNDcxZGEyNzNhNmQxNDU5MDIwMzMxMzk3OWI0Y2M3
14
+ YmVkYzU2ZDc5NjMwMzYyZjJmMjFkNWU2YjRlNzZlMDRiMWU3ZTJjNDhhYjdj
15
+ M2VhMTA1ZWY5M2Q3MmEyMzQxMmQ0YzY0OWQ3YmE3ZGNkOWQzMjY=
data/README.md CHANGED
@@ -19,7 +19,13 @@ Or install it yourself as:
19
19
  ## Usage
20
20
 
21
21
  ```ruby
22
- Sanistring.sanitize('../path/to/some/file', whitelist: 'abcdefghijklmnop')
22
+
23
+ # alphanumeric
24
+ Sanistring.sanitize('../path/to/some/file', whitelist: :alphanumeric)
25
+
26
+ # custom whitelist
27
+ Sanistring.sanitize('../path/to/some/file', whitelist: '+-*/=')
28
+
23
29
  ```
24
30
 
25
31
  ## Contributing
@@ -1,5 +1,4 @@
1
1
  require 'sanistring/version'
2
- require 'sanistring/list'
3
2
  require 'sanistring/sanitize'
4
3
 
5
4
  module Sanistring
@@ -4,9 +4,9 @@ module Sanistring
4
4
  sanitized = name.split('').map{ |char|
5
5
  if opts[:replace] && opts[:replace][char]
6
6
  opts[:replace][char]
7
- elsif opts[:whitelist].is_a?(Fixnum)
7
+ elsif opts[:whitelist].is_a?(Symbol)
8
8
  case opts[:whitelist]
9
- when List::AlphaNumeric
9
+ when :alpha_numeric, :alphanumeric
10
10
  char if !!(/[a-zA-Z0-9]/ =~ char)
11
11
  else
12
12
  nil
@@ -1,3 +1,3 @@
1
1
  module Sanistring
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
@@ -4,23 +4,23 @@ describe Sanistring do
4
4
 
5
5
  describe '#sanitize' do
6
6
  it 'removes prohibited characters' do
7
- Sanistring.sanitize('../abc', whitelist: Sanistring::List::AlphaNumeric).should == 'abc'
7
+ Sanistring.sanitize('../abc', whitelist: :alphanumeric).should == 'abc'
8
8
  end
9
9
 
10
10
  it 'replaces characters' do
11
- Sanistring.sanitize(' adam ', whitelist: Sanistring::List::AlphaNumeric, replace: {' '=> ''}).should == 'adam'
11
+ Sanistring.sanitize(' adam ', whitelist: :alphanumeric, replace: {' '=> ''}).should == 'adam'
12
12
  end
13
13
 
14
14
  it 'returns empty string when string is entirely prohibited characters' do
15
- Sanistring.sanitize('..', whitelist: Sanistring::List::AlphaNumeric).should == ''
15
+ Sanistring.sanitize('..', whitelist: :alphanumeric).should == ''
16
16
  end
17
17
 
18
18
  it 'upcases string' do
19
- Sanistring.sanitize('abc', upcase: true, whitelist: Sanistring::List::AlphaNumeric).should == 'ABC'
19
+ Sanistring.sanitize('abc', upcase: true, whitelist: :alphanumeric).should == 'ABC'
20
20
  end
21
21
 
22
22
  it 'downcases string' do
23
- Sanistring.sanitize('ABC', downcase: true, whitelist: Sanistring::List::AlphaNumeric,).should == 'abc'
23
+ Sanistring.sanitize('ABC', downcase: true, whitelist: :alphanumeric).should == 'abc'
24
24
  end
25
25
 
26
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sanistring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Hallett
@@ -66,7 +66,6 @@ files:
66
66
  - README.md
67
67
  - Rakefile
68
68
  - lib/sanistring.rb
69
- - lib/sanistring/list.rb
70
69
  - lib/sanistring/sanitize.rb
71
70
  - lib/sanistring/version.rb
72
71
  - sanistring.gemspec
@@ -1,6 +0,0 @@
1
- module Sanistring
2
- class List
3
- AlphaNumeric = 1
4
-
5
- end
6
- end