word-count-validator 0.2.1 → 0.2.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.
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ begin
9
9
  gem.description = %Q{Provides validates_word_count which lets users validate a string has a minimum / maximum number of words.}
10
10
  gem.email = "sutto@sutto.net"
11
11
  gem.homepage = "http://github.com/Sutto/word-count-validator"
12
- gem.authors = ["Darcy Laycock"]
12
+ gem.authors = ["Darcy Laycock", "Eric Anderson"]
13
13
  end
14
14
  Jeweler::GemcutterTasks.new
15
15
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -30,13 +30,14 @@ module ActiveModel
30
30
 
31
31
  def check_validity!
32
32
  raise ArgumentError, "You must provide a valid range for the number of words e.g. 2..100" if options.has_key?(:in)
33
- raise ArgumentError, "The min value must respond to to_i" unless options[:min].respond_to?(:to_i)
34
- raise ArgumentError, "The max value must respond to to_i" unless options[:max].respond_to?(:to_i)
33
+ raise ArgumentError, "The min value must respond to to_i or call" unless options[:min].respond_to?(:to_i) || options[:min].respond_to?(:call)
34
+ raise ArgumentError, "The max value must respond to to_i or call" unless options[:max].respond_to?(:to_i) || options[:max].respond_to?(:call)
35
35
  end
36
36
 
37
37
  def validate_each(record, attribute, value)
38
- min_words, max_words = options[:min].to_i, options[:max].to_i
39
- value = ActionController::Base.helpers.strip_tags(value).gsub(/ | /i, ' ') if options[:strip_tags]
38
+ min_words = options[:min].respond_to?(:call) ? options[:min][record, attribute, value] : options[:min].to_i
39
+ max_words = options[:max].respond_to?(:call) ? options[:max][record, attribute, value] : options[:max].to_i
40
+ value = ActionController::Base.helpers.strip_tags(value || '').gsub(/ | /i, ' ') if options[:strip_tags]
40
41
  value.gsub! /[.(),;:!?%#\$'"_+=\/-]*/, '' if options[:strip_punctuation]
41
42
  count = word_count_for(value)
42
43
  if !options[:skip_min] && 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.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Darcy Laycock"]
12
- s.date = %q{2010-12-01}
11
+ s.authors = ["Darcy Laycock", "Eric Anderson"]
12
+ s.date = %q{2010-12-11}
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,21 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: word-count-validator
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Darcy Laycock
14
+ - Eric Anderson
14
15
  autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-12-01 00:00:00 +08:00
19
+ date: 2010-12-11 00:00:00 +08:00
19
20
  default_executable:
20
21
  dependencies: []
21
22