summaryrefslogtreecommitdiff
path: root/fake-service/lib/pixelated_service/search/string_match.rb
diff options
context:
space:
mode:
authorBruno Wagner Goncalves <bwagner@thoughtworks.com>2014-08-01 17:49:13 -0300
committerBruno Wagner Goncalves <bwagner@thoughtworks.com>2014-08-01 17:49:13 -0300
commitf52efae271ddb376e7223405c3a74edd7ed598b9 (patch)
treebf76c588086b93452457c71bdbfa6cee0206c81f /fake-service/lib/pixelated_service/search/string_match.rb
parentd8360815ea07d9944f08ad378d2b89e64e1f2c9e (diff)
Changed names according to new convention on the fake service
Diffstat (limited to 'fake-service/lib/pixelated_service/search/string_match.rb')
-rw-r--r--fake-service/lib/pixelated_service/search/string_match.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/fake-service/lib/pixelated_service/search/string_match.rb b/fake-service/lib/pixelated_service/search/string_match.rb
new file mode 100644
index 00000000..f9b32376
--- /dev/null
+++ b/fake-service/lib/pixelated_service/search/string_match.rb
@@ -0,0 +1,37 @@
+module PixelatedService
+ class Search
+ class StringMatch
+ attr_reader :str
+ def initialize(data, quoted=false)
+ @str = data
+ @quoted = quoted
+ @data = Regexp.new(Regexp.quote(self.match_string), Regexp::IGNORECASE)
+ @exact_match = /^#{@data}$/
+ end
+
+ def match_string
+ if @quoted
+ @str[1..-2]
+ else
+ @str
+ end
+ end
+
+ def to_s
+ "String(#@data)"
+ end
+
+ def match_string?(str)
+ Array(str).any? { |ff| !!(ff[@data]) }
+ end
+
+ def match_exact_string?(str)
+ Array(str).any? { |ff| @exact_match.match ff }
+ end
+
+ def match?(mail)
+ match_string? [mail.to, mail.from, mail.subject, mail.body]
+ end
+ end
+ end
+end