The Array Comparator
Can be used to compare to arrays with a consistent api.
Installation
Add this line to your application's Gemfile:
gem 'the_array_comparator'
And then execute:
$ bundle
Or install it yourself as:
$ gem install the_array_comparator
Usage
Currently the following strategies are supported
Strategy | Description |
---|---|
:contains_all | True if all of the given keywords are part of the data |
:contains_any | True if any of the given keywords are part of the data |
:not_contains | True if the given keywords are not part of the data |
:contains_all_as_substring | True if all given keywords are a substring of an data element |
:contains_any_as_substring | True if any given keyword are a substring of an data element |
:not_contains_substring | True if none of the given keywords is a substring of an data element |
:is_equal | True if both, the keywords and the data, are identical |
:is_not_equal | True if the keywords are didfferent from the data |
Simple example
require 'the_array_comparator'
comparator = TheArrayComparator::Comparator.new
data = %w{ a b c d }
keyword_overlap = %w{ a b }
comparator.add_check data , :contains_all , keyword_overlap
result = comparator.success?
puts result #should be true
Example with substrings
require 'the_array_comparator'
comparator = TheArrayComparator::Comparator.new
data = %w{ acd b }
keyword_overlap = %w{ cd b }
comparator.add_check data , :contains_all_as_substring, keyword_overlap
result = comparator.success?
puts result #should be true
Example with exceptions
require 'the_array_comparator'
comparator = TheArrayComparator::Comparator.new
data = %w{ acd b }
keyword_overlap = %w{ a b }
exceptions = %w{ cd }
comparator.add_check data , :contains_all_as_substring, keyword_overlap, exceptions
result = comparator.success?
puts result #should be false
Extend the library
If you wish to write your own comparators you can do so. Just register those classes with a keyword.
c = TheArrayComparator::Comparator.new
c.register :my_contains, SearchingStrategies::MyContains
Further reading
Please the the full api-documentation on rdoc info for further reading. I just give you a brief overview of all the available methods. There's also a brief guide about howto discover the API.
Contributing
Please see CONTRIBUTIONS.md.
Copyright
(c) 2013 Max Meyer. All rights reserved. Please also see LICENSE.md.