pattern_matcher 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Adam Parker
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ Pattern Matcher
2
+ ============
3
+
4
+ Gem to help manage, test and run regex pattern matchers for a given project.
5
+
6
+ Gem can be found on rubygems at https://rubygems.org/gems/pattern_matcher
@@ -0,0 +1,17 @@
1
+ module PatternMatcher
2
+ class Config
3
+
4
+ attr_accessor :patterns_yml
5
+
6
+ def initialize
7
+ set_defaults
8
+ end
9
+
10
+ private
11
+
12
+ def set_defaults
13
+ @patterns_yml = File.join(File.dirname(__FILE__), "config", "patterns.yml")
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,48 @@
1
+ module PatternMatcher
2
+ class Matcher
3
+
4
+ def self.string_to_regex(string)
5
+ Regexp.new string if is_valid_regex_string?(string)
6
+ end
7
+
8
+ def self.match_pattern_in_text(pattern, text)
9
+ return pattern.match text if is_valid_pattern?(pattern) && is_valid_text?(text)
10
+ end
11
+
12
+ def self.initialize_patterns
13
+ raw_pattern_hash = load_yaml || {}
14
+ @@patterns = hash_to_patterns_array(raw_pattern_hash)
15
+ end
16
+
17
+ private
18
+
19
+ def self.is_valid_regex_string?(string)
20
+ !string.nil? && !string.empty?
21
+ end
22
+
23
+ def self.is_valid_pattern?(pattern)
24
+ !pattern.nil?
25
+ end
26
+
27
+ def self.is_valid_text?(text)
28
+ !text.nil? && !text.empty?
29
+ end
30
+
31
+ def self.load_yaml
32
+ YAML.load_file(PatternMatcher.configuration.patterns_yml) if PatternMatcher.configuration.patterns_yml
33
+ end
34
+
35
+ def self.hash_to_patterns_array(hash)
36
+ patterns = []
37
+ hash_patterns(hash).each do |a_pattern|
38
+ patterns << PatternMatcher::Pattern.new(a_pattern[1])
39
+ end
40
+ patterns
41
+ end
42
+
43
+ def self.hash_patterns(hash)
44
+ (hash["patterns"] || {}) if !hash.nil?
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,18 @@
1
+ module PatternMatcher
2
+ class Pattern
3
+
4
+ attr_accessor :name, :regex, :description
5
+
6
+ def initialize(hash)
7
+ if !hash.nil?
8
+ @name = hash["name"]
9
+ @regex = hash["regex"]
10
+ @description = hash["description"]
11
+ end
12
+ end
13
+
14
+ def is_valid?
15
+ return !(@regex.nil? || @regex.empty?)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module PatternMatcher
2
+ VERSION = "0.0.4"
3
+ end
@@ -3,10 +3,10 @@ require 'date'
3
3
 
4
4
  #gem includes
5
5
 
6
- require_relative "pattern_matcher/version"
7
- require_relative "pattern_matcher/config"
8
- require_relative "pattern_matcher/pattern"
9
- require_relative "pattern_matcher/matcher"
6
+ require "pattern_matcher/version"
7
+ require "pattern_matcher/config"
8
+ require "pattern_matcher/pattern"
9
+ require "pattern_matcher/matcher"
10
10
 
11
11
  module PatternMatcher
12
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pattern_matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -65,7 +65,13 @@ executables: []
65
65
  extensions: []
66
66
  extra_rdoc_files: []
67
67
  files:
68
+ - lib/pattern_matcher/config.rb
69
+ - lib/pattern_matcher/matcher.rb
70
+ - lib/pattern_matcher/pattern.rb
71
+ - lib/pattern_matcher/version.rb
68
72
  - lib/pattern_matcher.rb
73
+ - LICENSE
74
+ - README.md
69
75
  homepage: https://rubygems.org/gems/pattern_matcher
70
76
  licenses:
71
77
  - MIT