Class: Validation::Rule::TagCount
- Inherits:
-
Object
- Object
- Validation::Rule::TagCount
- Defined in:
- lib/diaspora_federation/validators/rules/tag_count.rb
Overview
Rule for validating the number of tags in a string. Only the “#” characters will be counted. The string can be nil.
Instance Attribute Summary collapse
-
#params ⇒ Hash
readonly
This rule must have a
maximum
param.
Instance Method Summary collapse
-
#error_key ⇒ Symbol
The error key for this rule.
-
#initialize(params) ⇒ TagCount
constructor
Creates a new rule for a maximum tag count validation.
-
#valid_value?(value) ⇒ Boolean
Determines if value doesn’t have more than
maximum
tags.
Constructor Details
#initialize(params) ⇒ TagCount
Creates a new rule for a maximum tag count validation
16 17 18 19 20 21 22 |
# File 'lib/diaspora_federation/validators/rules/tag_count.rb', line 16 def initialize(params) unless params.include?(:maximum) && params[:maximum].is_a?(Integer) raise ArgumentError, "A number has to be specified for :maximum" end @params = params end |
Instance Attribute Details
#params ⇒ Hash (readonly)
This rule must have a maximum
param.
11 12 13 |
# File 'lib/diaspora_federation/validators/rules/tag_count.rb', line 11 def params @params end |
Instance Method Details
#error_key ⇒ Symbol
The error key for this rule
26 27 28 |
# File 'lib/diaspora_federation/validators/rules/tag_count.rb', line 26 def error_key :tag_count end |
#valid_value?(value) ⇒ Boolean
Determines if value doesn’t have more than maximum
tags
31 32 33 |
# File 'lib/diaspora_federation/validators/rules/tag_count.rb', line 31 def valid_value?(value) value.nil? || value.count("#") <= params[:maximum] end |