scrubba 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba2ed8480e2ff0e7b1464159fc749eb67abca90b
4
- data.tar.gz: 7b2357f30b4a4e36e10db6892e3109e174040b9a
3
+ metadata.gz: 6bfa17fbe6fb61cebda1c7823c9d599f4eafc3e0
4
+ data.tar.gz: 551b5c9c6b4b9333f4d7a9ddb975605bb5e2c9d9
5
5
  SHA512:
6
- metadata.gz: 908262afc8c7d5fd63d1d7d1806e96609bb890ef30e00f0fdeb8fa5a35cf82e3c96cd3600c1b036bfd7888e1a9fe541c21f16bf612bdede2e314e3cfe13e558e
7
- data.tar.gz: fb318e8d2142aed98075667e5f23f09901bc1db536155d7e510b8020e8b0fa9e603a3b93f6603c3cb984477558a1b8d260fe1e7c491caedae2ab91eaf5fdedbd
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 with gems and
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.scrub(some_str) #=> "foo \t bar"
32
- Scrubba.normalize(some_str) #=> " foo bar "
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
- strip :title, :body
44
- normalize :title
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.scrub(str)
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.normalize(str)
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(keys, func)
8
- keys.each do |k|
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
- def scrub(*keys)
15
- before_validation { scrubba_apply(keys, :scrub) }
16
- end
17
-
18
- def normalize(*keys)
19
- before_validation { scrubba_apply(keys, :normalize) }
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
@@ -1,3 +1,3 @@
1
1
  module Scrubba
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.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-08-29 00:00:00.000000000 Z
11
+ date: 2015-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler