Sha256: 1d6f52ed8b19fb8b1885f083994e059f2596b84a6d70d2fb7fe6b1c8f1f801a3
Contents?: true
Size: 1.23 KB
Versions: 10
Compression:
Stored size: 1.23 KB
Contents
module Spidr class Rules # Accept rules attr_reader :accept # Reject rules attr_reader :reject def initialize(options={}) @accept = (options[:accept] || []) @reject = (options[:reject] || []) end # # Returns +true+ if the _field_ is accepted by the rules, # returns +false+ otherwise. # def accept?(field) unless @accept.empty? @accept.each do |rule| return true if test_field(field,rule) end return false else @reject.each do |rule| return false if test_field(field,rule) end return true end end # # Returns +true+ if the _field_ is rejected by the rules, # returns +false+ otherwise. # def reject?(field) !(accept?(field)) end protected # # Tests the specified _field_ against the specified _rule_. Returns # +true+ when the _rule_ matches the specified _field_, returns # +false+ otherwise. # def test_field(field,rule) if rule.kind_of?(Proc) return (rule.call(field) == true) elsif rule.kind_of?(Regexp) return !((field.to_s =~ rule).nil?) else return field == rule end end end end
Version data entries
10 entries across 10 versions & 1 rubygems