21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/mutation_set.rb', line 21
def criterion_ok? obj, attrib, value
case attrib
when /^min_(.*)/
v = obj.send($1.to_sym).to_f
return v >= value.to_f
when /^max_(.*)/
return obj.send($1.to_sym).to_f <= value.to_f
when /^exclude_(.*)/
v = obj.send($1.to_sym)
if value.is_a? Array
return value.none? { |r| v.match(/#{r}/) }
else
return v !~ /#{value}/
end
when /^has_(.*)/
v = obj.send($1.to_sym)
if value.is_a? Array
return value.include? v
elsif value == true
return v && (v.is_a?(String) ? v.size > 0 : v)
elsif value == false || value == "nil"
return !v
else
return value == v
end
when /^include_(.*)/
v = obj.send($1.to_sym)
if value.is_a? Array
return value.any? { |r| v.match(/#{r}/) }
else
return v =~ /#{value}/
end
when /^either.*/
v = nil
value.each do |attrib,val|
v = true if criterion_ok? obj, attrib, val
end
return v
when /^whitelisted/
whitelist = @table.whitelist value
return whitelist.intersect(self)
when /^blacklisted/
blacklist = @table.blacklist value
return !blacklist.intersect(self)
else
case value
when "nil", false, nil
return !obj.send(attrib.to_sym)
when true
return obj.send(attrib.to_sym)
end
end
true
end
|