Class: GeneSystem::StepCollection
- Inherits:
-
Object
- Object
- GeneSystem::StepCollection
- Extended by:
- Forwardable
- Defined in:
- lib/gene_system/step_collection.rb
Overview
Filterable and mergable collection of steps
Constant Summary collapse
- DEFAULT_QUERY =
Default filter will match each step
lambda do |_step, _query = {}| true end
- STEP_INCLUDE_ANY_TAG =
Function that returns true if step has any of the provided tags
lambda do |step, query = {}| raise 'query must include tags' unless query[:tags].is_a?(Array) results = query[:tags].map do |tag| step..include?(tag) end results.any?(true) end
- STEP_EXCLUDE_ANY_TAG =
Function that returns true if step does not have any of the provided tags
lambda do |step, query = {}| raise 'query must include tags' unless query[:tags].is_a?(Array) results = query[:tags].map do |tag| step..include?(tag) end results.all?(false) end
Instance Attribute Summary collapse
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
Instance Method Summary collapse
-
#filter(matcher = DEFAULT_FILTER, query = {}) ⇒ Object
Filters steps by given matcher function.
-
#initialize(steps = []) ⇒ StepCollection
constructor
A new instance of StepCollection.
-
#merge(collection) ⇒ GeneSystem::StepCollection
Creates a collection which is a union of the given collection and this collection.
Constructor Details
#initialize(steps = []) ⇒ StepCollection
Returns a new instance of StepCollection.
55 56 57 |
# File 'lib/gene_system/step_collection.rb', line 55 def initialize(steps = []) @steps = steps end |
Instance Attribute Details
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
6 7 8 |
# File 'lib/gene_system/step_collection.rb', line 6 def steps @steps end |
Instance Method Details
#filter(matcher = DEFAULT_FILTER, query = {}) ⇒ Object
Filters steps by given matcher function
The matcher function must take a step as an argument and return true or false as to whether it should be in the returned collection.
73 74 75 76 77 78 79 |
# File 'lib/gene_system/step_collection.rb', line 73 def filter(matcher = DEFAULT_FILTER, query = {}) GeneSystem::StepCollection.new( @steps.select do |step| matcher.call(step, query) end ) end |
#merge(collection) ⇒ GeneSystem::StepCollection
Creates a collection which is a union of the given collection and this collection.
90 91 92 93 94 |
# File 'lib/gene_system/step_collection.rb', line 90 def merge(collection) GeneSystem::StepCollection.new( @steps + collection.steps ) end |