word-count-validator 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -3,6 +3,12 @@
3
3
  A simple ActiveModel validator for requiring a model has a word count in a specific range.
4
4
  Uses a very basic method for generating the count (scans for \w+)
5
5
 
6
+ == Contributions
7
+
8
+ With thanks to the following people:
9
+
10
+ * Eric Anderson (github)[https://github.com/eric1234] - Contributed support for the +:strip_tags+ option and a bunch of bug fixes.
11
+
6
12
  == Note on Patches/Pull Requests
7
13
 
8
14
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -17,6 +17,7 @@ module ActiveModel
17
17
  options[:max] ||= 100
18
18
  options[:min] ||= 0
19
19
  options[:strip_tags] = true unless options.has_key?(:strip_tags)
20
+ options[:strip_punctuation] = true unless options.has_key?(:strip_punctuation)
20
21
  if options.has_key?(:in)
21
22
  range = options[:in]
22
23
  if range.present? && range.respond_to?(:min) && range.respond_to?(:max)
@@ -35,7 +36,8 @@ module ActiveModel
35
36
 
36
37
  def validate_each(record, attribute, value)
37
38
  min_words, max_words = options[:min].to_i, options[:max].to_i
38
- value = ActionController::Base.helpers.strip_tags value if options[:strip_tags]
39
+ value = ActionController::Base.helpers.strip_tags(value).gsub(/ | /i, ' ') if options[:strip_tags]
40
+ value.gsub! /[.(),;:!?%#\$'"_+=\/-]*/, '' if options[:strip_punctuation]
39
41
  count = word_count_for(value)
40
42
  if !options[:skip_min] && count < min_words
41
43
  record.errors.add attribute, :too_few_words, options_for(count, min_words)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{word-count-validator}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Darcy Laycock"]
12
- s.date = %q{2010-11-30}
12
+ s.date = %q{2010-12-01}
13
13
  s.description = %q{Provides validates_word_count which lets users validate a string has a minimum / maximum number of words.}
14
14
  s.email = %q{sutto@sutto.net}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: word-count-validator
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Darcy Laycock
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-30 00:00:00 +08:00
18
+ date: 2010-12-01 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21