class Validation::Rule::TagCount

Rule for validating the number of tags in a string. Only the “#” characters will be counted. The string can be nil.

Attributes

params[R]

This rule must have a maximum param. @return [Hash] params

Public Class Methods

new(params) click to toggle source

Creates a new rule for a maximum tag count validation @param [Hash] params @option params [Integer] :maximum maximum allowed tag count

# 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

Public Instance Methods

error_key() click to toggle source

The error key for this rule @return [Symbol] error key

# File lib/diaspora_federation/validators/rules/tag_count.rb, line 26
def error_key
  :tag_count
end
valid_value?(value) click to toggle source

Determines if value doesn’t have more than maximum tags

# File lib/diaspora_federation/validators/rules/tag_count.rb, line 31
def valid_value?(value)
  value.nil? || value.count("#") <= params[:maximum]
end