module SearchJsonData

Constants

VERSION

Private Instance Methods

is_match(collection, data_hash, condition = nil, precision = false) click to toggle source

return true when one or more values include one or more words or phrases @param collection [Array] words or phrases to search @param data_hash [Hash] a hash that contain values to search in its @param condition [String, nil] condition for negatives matches @param precision [Boolean, false] false by default, true is case sensitive @return [Boolean] true is any value or phrase match, otherwise false

# File lib/search_json_data/data_array.rb, line 87
def is_match(collection, data_hash, condition = nil, precision = false)
    all_matches = true
    collection.each do |text|
        match = false
        # in this loop if only one match return true
        data_hash.each_value do |value|
            if precision
                match = true if value.include? text
            else
                match = true if value.downcase.include? text.downcase
            end
            # to exclude array in negative search
            match = false if condition == "-" and value.include? ',' and text=='array'
        end
        all_matches = all_matches & match # if only one doesn't match return false
    end
    all_matches
end