class PatternMatcher::Pattern
Attributes
description[RW]
name[RW]
pattern_id[RW]
regex[RW]
regex_string[RW]
valid_examples[RW]
Public Class Methods
new(hash)
click to toggle source
# File lib/pattern_matcher/pattern.rb, line 7 def initialize(hash) if hash.is_a?(Hash) @pattern_id = hash[:pattern_id] @name = hash["name"] @regex_string = hash["regex"] @regex = Matcher.string_to_regex(@regex_string) @description = hash["description"] @valid_examples = hash["valid_examples"] || [] end end
Public Instance Methods
is_valid?()
click to toggle source
# File lib/pattern_matcher/pattern.rb, line 40 def is_valid? return !@regex.nil? && !@pattern_id.nil? end
pattern_example_valid?(example)
click to toggle source
# File lib/pattern_matcher/pattern.rb, line 44 def pattern_example_valid?(example) Matcher.match_regex_in_text(@regex, example) end
to_h()
click to toggle source
# File lib/pattern_matcher/pattern.rb, line 30 def to_h { :name => @name, :is_valid => is_valid?, :regex_string => @regex_string, :description => @description, :valid_examples => @valid_examples } end
to_s()
click to toggle source
# File lib/pattern_matcher/pattern.rb, line 26 def to_s "#{@name} (#{is_valid?}) -- #{@regex_string} -- #{@description}" end
validate_all_examples()
click to toggle source
# File lib/pattern_matcher/pattern.rb, line 18 def validate_all_examples failures = [] @valid_examples.each do |example| failures << example if !pattern_example_valid? example end failures end