class PatternMatcher::PatternManager
Attributes
patterns_hash[RW]
Public Class Methods
initialize_patterns()
click to toggle source
# File lib/pattern_matcher/pattern_manager.rb, line 6 def self.initialize_patterns raw_pattern_hash = load_yaml || {} PatternManager.new_from_raw_hash raw_pattern_hash end
new(pattern_hash)
click to toggle source
# File lib/pattern_matcher/pattern_manager.rb, line 20 def initialize(pattern_hash) @patterns_hash = pattern_hash end
new_from_raw_hash(raw_hash)
click to toggle source
# File lib/pattern_matcher/pattern_manager.rb, line 11 def self.new_from_raw_hash(raw_hash) patterns = {} hash_patterns(raw_hash).each_pair do |a_key, a_pattern| a_pattern[:pattern_id] = a_key patterns[a_key] = PatternMatcher::Pattern.new(a_pattern) end PatternManager.new(patterns) end
Private Class Methods
hash_patterns(hash)
click to toggle source
# File lib/pattern_matcher/pattern_manager.rb, line 60 def self.hash_patterns(hash) (hash["patterns"] || {}) if !hash.nil? end
load_yaml()
click to toggle source
# File lib/pattern_matcher/pattern_manager.rb, line 56 def self.load_yaml YAML.load_file(PatternMatcher.configuration.patterns_yml) if PatternMatcher.configuration.patterns_yml end
Public Instance Methods
add_pattern(pattern)
click to toggle source
# File lib/pattern_matcher/pattern_manager.rb, line 24 def add_pattern(pattern) @patterns_hash[pattern.pattern_id] = pattern if pattern.is_valid? end
count()
click to toggle source
# File lib/pattern_matcher/pattern_manager.rb, line 50 def count @patterns_hash.keys.count || 0 end
each() { |pattern| ... }
click to toggle source
# File lib/pattern_matcher/pattern_manager.rb, line 44 def each @patterns_hash.values.each do |pattern| yield pattern end end
keys()
click to toggle source
# File lib/pattern_matcher/pattern_manager.rb, line 28 def keys @patterns_hash.keys end
to_a()
click to toggle source
# File lib/pattern_matcher/pattern_manager.rb, line 40 def to_a @patterns_hash.values end
to_s()
click to toggle source
# File lib/pattern_matcher/pattern_manager.rb, line 32 def to_s ret_str = "" @patterns_hash.values.each do |pattern| ret_str += pattern.to_s + "\n" end ret_str end