# The Array Comparator [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/maxmeyer/the_array_comparator) [![Build Status](https://travis-ci.org/maxmeyer/the_array_comparator.png?branch=master)](https://travis-ci.org/maxmeyer/the_array_comparator) Can be used to compare to arrays with a consistent api. ## Installation Add this line to your application's Gemfile: gem 'comparator' And then execute: $ bundle Or install it yourself as: $ gem install 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 ```ruby 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 ```ruby 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 ```ruby 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. ```ruby TheArrayComparator::Comparator.register :my_contains, Strategies::MyContains ``` ## Contributing Please see CONTRIBUTIONS.md ## Copyright (c) 2013 Max Meyer. All rights reserved. Please also see LICENSE.md