Class: Dynamican::Skimmer
- Inherits:
-
Object
- Object
- Dynamican::Skimmer
- Defined in:
- lib/dynamican/skimmer.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#item_name ⇒ Object
readonly
Returns the value of attribute item_name.
-
#skimming_instances ⇒ Object
readonly
Returns the value of attribute skimming_instances.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
-
#initialize(subject, collection, item_name, skimming_instances) ⇒ Skimmer
constructor
A new instance of Skimmer.
- #skim ⇒ Object
Constructor Details
#initialize(subject, collection, item_name, skimming_instances) ⇒ Skimmer
Returns a new instance of Skimmer.
5 6 7 8 9 10 |
# File 'lib/dynamican/skimmer.rb', line 5 def initialize(subject, collection, item_name, skimming_instances) @subject = subject @collection = collection @item_name = calculate_item_name @skimming_instances = skimming_instances end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
3 4 5 |
# File 'lib/dynamican/skimmer.rb', line 3 def collection @collection end |
#item_name ⇒ Object (readonly)
Returns the value of attribute item_name.
3 4 5 |
# File 'lib/dynamican/skimmer.rb', line 3 def item_name @item_name end |
#skimming_instances ⇒ Object (readonly)
Returns the value of attribute skimming_instances.
3 4 5 |
# File 'lib/dynamican/skimmer.rb', line 3 def skimming_instances @skimming_instances end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
3 4 5 |
# File 'lib/dynamican/skimmer.rb', line 3 def subject @subject end |
Instance Method Details
#skim ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dynamican/skimmer.rb', line 12 def skim set_instance_variables filters_rules = subject.filters.for_item(item_name).map(&:rules).flatten.map(&:statement) return collection if filters_rules.empty? skimming_result = collection.select do |collection_item| instance_variable_set("@#{item_name.downcase}", collection_item) filters_rules.all? { |rule| eval rule } end skimming_result end |