Class: CPS::Validator
- Inherits:
-
Struct
- Object
- Struct
- CPS::Validator
- Defined in:
- lib/cps-client/validator.rb
Overview
CPS::Validator.load d = CPS::Validator.find(:domain) d.name => :domain d.valid?(“qutic.com”) => true
Instance Attribute Summary collapse
-
#max ⇒ Object
Returns the value of attribute max.
-
#min ⇒ Object
Returns the value of attribute min.
-
#name ⇒ Object
Returns the value of attribute name.
-
#regexp ⇒ Object
Returns the value of attribute regexp.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#max ⇒ Object
Returns the value of attribute max
8 9 10 |
# File 'lib/cps-client/validator.rb', line 8 def max @max end |
#min ⇒ Object
Returns the value of attribute min
8 9 10 |
# File 'lib/cps-client/validator.rb', line 8 def min @min end |
#name ⇒ Object
Returns the value of attribute name
8 9 10 |
# File 'lib/cps-client/validator.rb', line 8 def name @name end |
#regexp ⇒ Object
Returns the value of attribute regexp
8 9 10 |
# File 'lib/cps-client/validator.rb', line 8 def regexp @regexp end |
Class Method Details
.find(key) ⇒ Object
23 24 25 |
# File 'lib/cps-client/validator.rb', line 23 def self.find(key) @@all[key] end |
.load ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cps-client/validator.rb', line 11 def self.load return @@all if @@all.present? data_file = File.join(File.dirname(__FILE__), '..', '..', 'data', 'validation.yml') @@all = {} YAML.load(File.read(data_file)).each_pair do |key, c| @@all[key.to_sym] = Validator.new(key.to_sym, c[:regexp], c[:min], c[:max]) end @@all end |
Instance Method Details
#to_s ⇒ Object
27 28 29 |
# File 'lib/cps-client/validator.rb', line 27 def to_s name.to_s end |
#valid?(value) ⇒ Boolean
31 32 33 34 35 36 |
# File 'lib/cps-client/validator.rb', line 31 def valid?(value) !value.nil? && value.length >= self.min && value.length <= self.max && !regexp.match(value).nil? end |