Class: Jschematic::Attributes::Pattern
- Inherits:
-
Object
- Object
- Jschematic::Attributes::Pattern
- Includes:
- Element
- Defined in:
- lib/jschematic/attributes/pattern.rb
Instance Attribute Summary
Attributes included from Element
Instance Method Summary collapse
- #accepts?(instance) ⇒ Boolean
-
#initialize(pattern) ⇒ Pattern
constructor
A new instance of Pattern.
Methods included from Element
#required?, #schema_for, #title, #to_s
Constructor Details
#initialize(pattern) ⇒ Pattern
Returns a new instance of Pattern.
8 9 10 |
# File 'lib/jschematic/attributes/pattern.rb', line 8 def initialize(pattern) @pattern = Regexp.new(pattern) end |
Instance Method Details
#accepts?(instance) ⇒ Boolean
12 13 14 15 |
# File 'lib/jschematic/attributes/pattern.rb', line 12 def accepts?(instance) return true unless String === instance instance.match(@pattern) || fail_validation!("string matching #{@pattern}", instance) end |