str_sanitizer 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b538c943e4d55ad6963787e0959efa1bdc2c22e1
4
- data.tar.gz: d0c9877e414a122aba5837fcf040e96e8f3064ea
3
+ metadata.gz: 40adee975fa727815aab7c0c5342b29aa314141d
4
+ data.tar.gz: 61bf3734eb9e0498d0340c336c906279b29accc6
5
5
  SHA512:
6
- metadata.gz: e6c2d75091881c70ade7114a0e057df01e338d43221a6d3882b39ff4aa0b798a25e352911a1240a0a0afc8b11503fe4dc75b0884ada0a7985beb6fb59e7e64c7
7
- data.tar.gz: 8c5da11e494e9d36f4734c7d1cfc543a81a8d707d7aa7738d14e925380cd35c76538b348d7f75f321dc0a03053726e2f5ed2d021c5a502b92c705f9384f30854
6
+ metadata.gz: 3ef826fb0f755c512fd636b6ba678041191517af6c6ba62f716ef17fe248022a8368ec38bf0339d06c055151930eebec476670adfd7161ccc590cbddc06f5832
7
+ data.tar.gz: 07efaf0dac8247d325828b0711dd4f13e8d9310a42b4818a6470e4536ee8b6e1efb286cbdf7a715d68dd69e00cd8e61bdb8b2ddfdfc6142c90abeb9ed85dabc0
data/.travis.yml CHANGED
@@ -1,5 +1,14 @@
1
1
  sudo: false
2
+
2
3
  language: ruby
4
+
3
5
  rvm:
4
6
  - 2.3.1
7
+ - 2.1.5
8
+ - 2.0.0
9
+ - 1.9.3
10
+
5
11
  before_install: gem install bundler -v 1.15.3
12
+
13
+ notifications:
14
+ email: false
data/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
+ ## StrSanitizer 0.2.0 (August 09, 2017) ##
2
+
3
+ * Changed the structure of the module in `lib/str_sanitizer/quotes.rb` file. Removed the `InstanceMethods` module and `included` class method of `Quotes` module. Remove the `ClassMethods` class too from `Quotes` module. Re-structured the whole module.
4
+ * Use `extend` instead of `include` in `StrSanitizer` class for using other modules methods. (To use the instance methods of any modules as class methods)
5
+ * Add documentation about the methods in `Quotes` module.
6
+
1
7
  ## StrSanitizer 0.1.1 (August 07, 2017) ##
2
8
 
3
9
  * In v0.1.0, the single_quote method wasn't working properly. This release fixes it.
4
- *
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Gem Version](https://badge.fury.io/rb/str_sanitizer.svg)](https://badge.fury.io/rb/str_sanitizer)
1
2
  # StrSanitizer
2
3
 
3
4
  Welcome to this gem. This gem is about String Sanitization. This gem sanitizes the string which is given.
@@ -21,15 +22,30 @@ Or install it yourself as:
21
22
 
22
23
  ## Usage
23
24
 
24
- ##### To escape quotes of a string
25
+ - To escape quotes of a string
25
26
  ```ruby
26
27
  require "str_sanitizer"
27
28
 
28
- hello = "He said, 'Hello!'"
29
- StrSanitizer.double_quote hello # => He said, \'Hello!\'
29
+ hello = 'He said, "Hello!"'
30
+ StrSanitizer.double_quote(hello) # => He said, \"Hello!\"
30
31
 
31
- hello = 'She said, "Hello!"'
32
- StrSanitizer.single_quote hello # => She said, \"Hello!\"
32
+ hello = "She said, 'Hello!'"
33
+ StrSanitizer.single_quote(hello) # => She said, \'Hello!\'
34
+
35
+ both_quotes = "They said, \"Don't do it!\""
36
+ StrSanitizer.both_quotes(both_quotes) # => They said, \"Don\'t do it!\"
37
+ ```
38
+ You can also check if the string has any quote or not
39
+ ```ruby
40
+ no_quote = "Hello, there."
41
+ single_quote = "It's going down."
42
+ double_quote = "He said, \"Hello\""
43
+
44
+ StrSanitizer.has_any_quote?(no_quote) # => nil
45
+ StrSanitizer.has_both_quotes?(no_quote) # => nil
46
+
47
+ StrSanitizer.has_single_quotes?(single_quote) # => true
48
+ StrSanitizer.has_double_quotes?(double_quote) # => true
33
49
  ```
34
50
 
35
51
  ## Development
@@ -1,21 +1,95 @@
1
+
1
2
  class StrSanitizer
3
+
4
+ # This module sanitizes the given string by adding backslash (\) before quote
5
+ # It also can check if a string has any quote or not.
6
+ #
7
+ # Author: Jakaria (mailto: jakariablaine120@gmail.com)
8
+ # Copyright: Copyright (c) 2017 Jakaria
9
+
2
10
  module Quotes
3
- def self.included(base)
4
- base.send(:include, InstanceMethods)
5
- base.send(:extend, ClassMethods)
11
+
12
+ # Find any double quote (") in a string and add backslash (\) before the double quote.
13
+ #
14
+ # Params:
15
+ # +str+:: A +string+ which has double quote that needs to be escaped.
16
+ #
17
+ # Returns:
18
+ # +String+:: The string which was passed to the parameter with escaped double quotes.
19
+ def double_quote(str)
20
+ str.gsub(/"/, /\\"/.source)
6
21
  end
7
22
 
8
- module InstanceMethods
23
+ # Find any single quote (') in a string and add backslash (\) before the single quote.
24
+ #
25
+ # Params:
26
+ # +str+:: A +string+ which has single quote that needs to be escaped.
27
+ #
28
+ # Returns:
29
+ # +String+:: The string which was passed to the parameter with escaped single quotes.
30
+ def single_quote(str)
31
+ str.gsub(/'/, /\\'/.source)
9
32
  end
10
33
 
11
- module ClassMethods
12
- def double_quote(str)
13
- str.gsub(/"/, /\\"/.source)
14
- end
34
+ # Find any single quote (') and double quote (") in a string and add backslash (\)
35
+ # before the single quote and double quote (").
36
+ #
37
+ # Params:
38
+ # +str+:: A +string+ which has single quote and double quote that need to be escaped.
39
+ #
40
+ # Returns:
41
+ # +String+:: The string which was passed to the parameter with escaped single quote and
42
+ # double quote.
43
+ def both_quotes(str)
44
+ single_quote(double_quote(str))
45
+ end
46
+
47
+ # Search through the given string to see if it has any single quote (').
48
+ #
49
+ # Params:
50
+ # +str+:: A +string+ which needs to be checked for single quote.
51
+ # +pos+:: From where it should start searching. +Default+ is 0.
52
+ #
53
+ # Returns:
54
+ # +Boolean|Nil+:: Returns true if it has any single quote, nil for no single quote
55
+ def has_single_quote?(str, pos = 0)
56
+ true if str.match("'", pos)
57
+ end
58
+
59
+ # Search through the given string to see if it has any double quote (").
60
+ #
61
+ # Params:
62
+ # +str+:: A +string+ which needs to be checked for double quote.
63
+ # +pos+:: From where it should start searching. +Default+ is 0.
64
+ #
65
+ # Returns:
66
+ # +Boolean|Nil+:: Returns true if it has any double quote, nil for no double quote
67
+ def has_double_quote?(str, pos = 0)
68
+ true if str.match('"', pos)
69
+ end
70
+
71
+ # Search through the given string to see if it has both, single (') and double quote (").
72
+ #
73
+ # Params:
74
+ # +str+:: A +string+ which needs to be checked for both quotes.
75
+ # +pos+:: From where it should start searching. +Default+ is 0.
76
+ #
77
+ # Returns:
78
+ # +Boolean|Nil+:: Returns true if it has both quotes, nil for no quote.
79
+ def has_both_quotes?(str, pos = 0)
80
+ true if has_single_quote?(str, pos) && has_double_quote?(str, pos)
81
+ end
15
82
 
16
- def single_quote(str)
17
- str.gsub(/'/, /\\'/.source)
18
- end
83
+ # Search through the given string to see if it has any quote.
84
+ #
85
+ # Params:
86
+ # +str+:: A +string+ which needs to be checked for any quote.
87
+ # +pos+:: From where it should start searching. +Default+ is 0.
88
+ #
89
+ # Returns:
90
+ # +Boolean|Nil+:: Returns true if it has any quote, nil for no quote
91
+ def has_any_quote?(str, pos = 0)
92
+ true if has_single_quote?(str, pos) || has_double_quote?(str, pos)
19
93
  end
20
94
  end
21
95
  end
@@ -1,3 +1,3 @@
1
1
  class StrSanitizer
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/str_sanitizer.rb CHANGED
@@ -1,6 +1,28 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (c) 2017 Jakaria Blaine
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
1
23
  require "str_sanitizer/version"
2
24
  require "str_sanitizer/quotes"
3
25
 
4
26
  class StrSanitizer
5
- include Quotes
27
+ extend Quotes
6
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: str_sanitizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakaria Blaine
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-07 00:00:00.000000000 Z
11
+ date: 2017-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler