Class: HashFilterer
- Inherits:
-
Object
- Object
- HashFilterer
- Defined in:
- lib/hash_filterer.rb
Overview
Can be used to check if a given hash respects a list of rules
Defined Under Namespace
Classes: Rule
Instance Attribute Summary collapse
-
#error_messages ⇒ Object
readonly
Returns the value of attribute error_messages.
Instance Method Summary collapse
- #accept?(hash) ⇒ Boolean
-
#initialize(rules) ⇒ HashFilterer
constructor
A new instance of HashFilterer.
Constructor Details
#initialize(rules) ⇒ HashFilterer
Returns a new instance of HashFilterer.
94 95 96 97 |
# File 'lib/hash_filterer.rb', line 94 def initialize(rules) @rules = [] (rules || []).each { |r| add_rule r } end |
Instance Attribute Details
#error_messages ⇒ Object (readonly)
Returns the value of attribute error_messages.
92 93 94 |
# File 'lib/hash_filterer.rb', line 92 def end |
Instance Method Details
#accept?(hash) ⇒ Boolean
99 100 101 102 103 104 105 106 |
# File 'lib/hash_filterer.rb', line 99 def accept?(hash) = [] @rules.all? do |rule| ok = rule.accept? hash << rule. unless ok ok end end |