Class: Jschematic::Attributes::Pattern

Inherits:
Object
  • Object
show all
Includes:
Element
Defined in:
lib/jschematic/attributes/pattern.rb

Instance Attribute Summary

Attributes included from Element

#id, #parent

Instance Method Summary collapse

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

Returns:

  • (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