Class: Company::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/company/collection.rb

Overview

A list of records an account holds, walked however the platform pages it and narrowed to a window measured from now, or to one technician. A gem answers each, and between with the same list narrowed to what starts between two moments, either one open.

Direct Known Subclasses

Selection, Visits, Windows

Instance Method Summary collapse

Instance Method Details

#ids ⇒ Array<String>

Returns ID of every record, the list walked; a platform with a cheaper way to ask answers it that way instead.

Returns:

  • (Array<String>) —

    ID of every record, the list walked; a platform with a cheaper way to ask answers it that way instead.



45
# File 'lib/company/collection.rb', line 45

def ids = map(&:id)

#includes(*names) ⇒ Collection

What to bring back beside each record, for a platform that charges for the asking. One that answers a record whole has nothing to ask for and answers the same list, so a caller names what it reads without knowing which kind of platform it is talking to.

Parameters:

  • names (Array<Symbol, Hash>) —

    what to read beside each record, as the gem names them.

Returns:

  • (Collection) —

    the same list, bringing those back where that costs anything.



28
# File 'lib/company/collection.rb', line 28

def includes(*names) = self

#of(id) ⇒ Collection

A platform that can ask its server for one technician's work narrows the list there; one that cannot walks the list and keeps what they turn out to be on. It takes the ID the platform files them under rather than the technician, that being the whole of what any platform asks by: a caller holding a record of its own then names the ID it knows, rather than dressing it up as a technician it does not have.

Parameters:

  • id (String) —

    ID the platform files whoever the work is booked for under.

Returns:

  • (Collection) —

    the same list, narrowed to theirs.



37
38
39
40
41
# File 'lib/company/collection.rb', line 37

def of(id)
  Selection.new(collection: self) do |record|
    record.technicians.any? { |technician| technician.id == id }
  end
end

#past(within = nil) ⇒ Collection

Returns the same list, narrowed to what started before now.

Parameters:

  • within (ActiveSupport::Duration, nil) (defaults to: nil) —

    how far back to look, or as far as there is.

Returns:

  • (Collection) —

    the same list, narrowed to what started before now.



18
19
20
21
# File 'lib/company/collection.rb', line 18

def past(within = nil)
  now = Time.now
  between within && now - within, now
end

#upcoming(within = nil) ⇒ Collection

Both ends are measured from one moment, so nothing slides between them.

Parameters:

  • within (ActiveSupport::Duration, nil) (defaults to: nil) —

    how far ahead to look, or as far as there is.

Returns:

  • (Collection) —

    the same list, narrowed to what starts from now on.



11
12
13
14
# File 'lib/company/collection.rb', line 11

def upcoming(within = nil)
  now = Time.now
  between now, within && now + within
end