scrubba 0.2.0 → 0.3.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 +4 -4
- data/CHANGELOG.md +12 -2
- data/README.md +6 -4
- data/lib/scrubba.rb +2 -2
- data/lib/scrubba/active_methods.rb +10 -10
- data/lib/scrubba/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bfa17fbe6fb61cebda1c7823c9d599f4eafc3e0
|
4
|
+
data.tar.gz: 551b5c9c6b4b9333f4d7a9ddb975605bb5e2c9d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2123ec2402ffddeeb1e689e8da27db805764b805889d61f131e0e0feb62f20f9b7fc6368a889139163e9041f955cfe0035293788abddf2bb5bec9856fa806db6
|
7
|
+
data.tar.gz: 21e5300f8c77ef6761e023b62b13d54ed9ed01f723038d57d90c5c1f7256d8b76de123ea7f1d4037e81a1021d5ab4d1cfc34dc5f2c1359fe1c5ed8fb12810b8f
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,17 @@
|
|
1
|
+
# 0.3.0 (2015-09-01)
|
2
|
+
|
3
|
+
- *BREAKING CHANGE*: `scrub` and `normalize` have been renamed to
|
4
|
+
`strip` and `collapse` based on usage and feedback
|
5
|
+
([#1](https://github.com/jmdeldin/scrubba/pull/1)). The new way to
|
6
|
+
declare which attributes you want to strip/collapse whitespace from
|
7
|
+
is:
|
8
|
+
|
9
|
+
scrub :some_attr, strip: true, collapse: true
|
10
|
+
|
1
11
|
# 0.2.0 (2015-08-29)
|
2
12
|
|
3
|
-
- Switched from `extend` to `include` for consistency
|
4
|
-
DRY-er code
|
13
|
+
- *BREAKING CHANGE*: Switched from `extend` to `include` for consistency
|
14
|
+
with gems and DRY-er code
|
5
15
|
|
6
16
|
# 0.1.0 (2015-08-28)
|
7
17
|
|
data/README.md
CHANGED
@@ -28,8 +28,8 @@ Standalone:
|
|
28
28
|
require "scrubba"
|
29
29
|
|
30
30
|
some_str = " foo \t bar "
|
31
|
-
Scrubba.
|
32
|
-
Scrubba.
|
31
|
+
Scrubba.strip(some_str) #=> "foo \t bar"
|
32
|
+
Scrubba.collapse(some_str) #=> " foo bar "
|
33
33
|
```
|
34
34
|
|
35
35
|
In an ActiveRecord model:
|
@@ -40,8 +40,8 @@ require "scrubba"
|
|
40
40
|
class Post < ActiveRecord::Base
|
41
41
|
include Scrubba::ActiveMethods
|
42
42
|
|
43
|
-
|
44
|
-
|
43
|
+
scrub :title, :slug, strip: true
|
44
|
+
scrub :body, collapse: true
|
45
45
|
end
|
46
46
|
```
|
47
47
|
|
@@ -49,6 +49,8 @@ end
|
|
49
49
|
|
50
50
|
Bug reports and pull requests are welcome on GitHub at https://github.com/jmdeldin/scrubba.
|
51
51
|
|
52
|
+
Protip: If you use Emacs, insert a Unicode space in your test data with <kbd>M-x insert-char</kbd> and verify it with <kbd>M-x describe-char</kbd>.
|
53
|
+
|
52
54
|
## License
|
53
55
|
|
54
56
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/scrubba.rb
CHANGED
@@ -7,7 +7,7 @@ module Scrubba
|
|
7
7
|
#
|
8
8
|
# @param [String] str
|
9
9
|
# @return [String]
|
10
|
-
def self.
|
10
|
+
def self.strip(str)
|
11
11
|
str.gsub(/(\A[[:space:]]+|[[:space:]]+\z)/, "") if str
|
12
12
|
end
|
13
13
|
|
@@ -15,7 +15,7 @@ module Scrubba
|
|
15
15
|
#
|
16
16
|
# @param [String] str
|
17
17
|
# @return [String]
|
18
|
-
def self.
|
18
|
+
def self.collapse(str)
|
19
19
|
str.gsub(/[[:space:]]+/, " ") if str
|
20
20
|
end
|
21
21
|
end
|
@@ -4,19 +4,19 @@ module Scrubba
|
|
4
4
|
base.extend(ClassMethods)
|
5
5
|
end
|
6
6
|
|
7
|
-
def scrubba_apply(
|
8
|
-
|
9
|
-
self[k] = Scrubba.public_send(func, self[k]) if self[k].present?
|
10
|
-
end
|
7
|
+
def scrubba_apply(key, func)
|
8
|
+
self[key] = Scrubba.public_send(func, self[key]) if self[key].present?
|
11
9
|
end
|
12
10
|
|
13
11
|
module ClassMethods
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
# Strip and/or collapse whitespace from given attributes.
|
13
|
+
def scrub(*keys, strip: false, collapse: false)
|
14
|
+
before_validation do
|
15
|
+
keys.each do |k|
|
16
|
+
scrubba_apply(k, :strip) if strip
|
17
|
+
scrubba_apply(k, :collapse) if collapse
|
18
|
+
end
|
19
|
+
end
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/lib/scrubba/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scrubba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon-Michael Deldin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|