Class: Company::Selection

Inherits:
Collection show all
Defined in:
lib/company/selection.rb

Overview

A list narrowed by something the platform could not be asked to narrow by: the list it came from is walked as it was, and only what the rule keeps comes through.

Instance Method Summary collapse

Methods inherited from Collection

#ids, #includes, #of, #past, #upcoming

Constructor Details

#initialize(collection:) {|Resource| ... } ⇒ Selection

Returns a new instance of Selection.

Parameters:

Yields:

  • (Resource) —

    each record of it, to keep or to let go.



7
8
9
10
# File 'lib/company/selection.rb', line 7

def initialize(collection:, &kept)
  @collection = collection
  @kept = kept
end

Instance Method Details

#between(from, to) ⇒ Selection

Returns the same rule, over the list narrowed to the window.

Parameters:

  • from (Time, nil) —

    moment the window opens, or nothing for as far back as it goes.

  • to (Time, nil) —

    moment the window closes, or nothing for as far ahead as it goes.

Returns:

  • (Selection) —

    the same rule, over the list narrowed to the window.



20
# File 'lib/company/selection.rb', line 20

def between(from, to) = self.class.new(collection: @collection.between(from, to), &@kept)

#each {|Resource| ... } ⇒ Object

Yields:

  • (Resource) —

    each record the rule kept, in the order the list answered it.



13
14
15
# File 'lib/company/selection.rb', line 13

def each
  @collection.each { |record| yield record if @kept.call record }
end