Class: BaseProcess
- Inherits:
-
Object
- Object
- BaseProcess
- Defined in:
- lib/base_process.rb
Overview
file: lib/base_process.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #deep_match(input, predicate) ⇒ Object
-
#initialize(key) ⇒ BaseProcess
constructor
A new instance of BaseProcess.
Constructor Details
#initialize(key) ⇒ BaseProcess
Returns a new instance of BaseProcess.
8 9 10 |
# File 'lib/base_process.rb', line 8 def initialize(key) @key = key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/base_process.rb', line 6 def key @key end |
Instance Method Details
#deep_match(input, predicate) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/base_process.rb', line 12 def deep_match(input, predicate) matches = [] # If the current input is a Hash, iterate over each key-value pair if input.is_a?(Hash) input.each do |key, value| # If the value matches the predicate, add it to matches if predicate.call(key, value) matches << value end # Continue searching deeper within the value matches.concat(deep_match(value, predicate)) end # If the input is an Array, iterate over each item elsif input.is_a?(Array) input.each do |item| # Continue searching within each item of the array matches.concat(deep_match(item, predicate)) end end matches end |