Class: NxtSchema::Validators::Pattern
- Defined in:
- lib/nxt_schema/validators/pattern.rb
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(pattern) ⇒ Pattern
constructor
A new instance of Pattern.
Methods inherited from Validator
Constructor Details
#initialize(pattern) ⇒ Pattern
Returns a new instance of Pattern.
4 5 6 |
# File 'lib/nxt_schema/validators/pattern.rb', line 4 def initialize(pattern) @pattern = pattern end |
Instance Attribute Details
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
9 10 11 |
# File 'lib/nxt_schema/validators/pattern.rb', line 9 def pattern @pattern end |
Instance Method Details
#build ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/nxt_schema/validators/pattern.rb', line 11 def build lambda do |node, value| if value.match(pattern) true else = translate_error(node.locale, value: value, pattern: pattern) node.add_error() false end end end |