Class: UsernameNotReservedValidator::Validator
- Inherits:
-
Object
- Object
- UsernameNotReservedValidator::Validator
- Defined in:
- lib/username_not_reserved_validator/validator.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ case_insensitive: true }
Instance Method Summary collapse
-
#initialize(username, options = {}) ⇒ Validator
constructor
A new instance of Validator.
- #valid? ⇒ Boolean
Constructor Details
#initialize(username, options = {}) ⇒ Validator
Returns a new instance of Validator.
5 6 7 8 9 10 11 12 13 |
# File 'lib/username_not_reserved_validator/validator.rb', line 5 def initialize(username, = {}) @username = username = DEFAULT_OPTIONS.merge() # patch for historical typo if .key?(:case_insencitive) [:case_insensitive] = [:case_insencitive] end end |
Instance Method Details
#valid? ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/username_not_reserved_validator/validator.rb', line 15 def valid? additional_reserved_names = [:additional_reserved_names] || [] words = ReservedNames.list + additional_reserved_names words += words.map(&:pluralize) if [:case_insensitive] words.map!(&:downcase) username = @username.downcase else username = @username end words.include?(username).! end |