Class: Ephem::Segments::SegmentGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/ephem/segments/segment_group.rb

Overview

Several segments that share the same key (an SPK center/target pair, or a PCK body) but cover different, contiguous time intervals. Each query is routed to the segment covering the requested time, so a body that a kernel splits across several intervals behaves as a single, continuous source.

SPK and PCK only build a group when a key actually has more than one segment; the common single-segment case returns the bare segment, so this routing never sits in the hot path for it.

Subclasses (PositionGroup, OrientationGroup) add the query methods appropriate to the segments they hold.

Direct Known Subclasses

OrientationGroup, PositionGroup

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(segments) ⇒ SegmentGroup

Returns a new instance of SegmentGroup.

Parameters:

  • segments (Array<BaseSegment>)

    segments sharing the same key



31
32
33
# File 'lib/ephem/segments/segment_group.rb', line 31

def initialize(segments)
  @segments = segments
end

Instance Attribute Details

#segmentsArray<BaseSegment> (readonly)

Returns the underlying segments.

Returns:



28
29
30
# File 'lib/ephem/segments/segment_group.rb', line 28

def segments
  @segments
end

Class Method Details

.wrap(segments) ⇒ BaseSegment, SegmentGroup

Wraps segments that share a key. A single segment is returned as-is, so the common case carries no routing overhead; only a key spanning several time intervals becomes a group.

Parameters:

  • segments (Array<BaseSegment>)

    segments sharing the same key

Returns:



23
24
25
# File 'lib/ephem/segments/segment_group.rb', line 23

def self.wrap(segments)
  segments.one? ? segments.first : new(segments)
end

Instance Method Details

#clear_datavoid

This method returns an undefined value.

Clears cached data for every segment in the group.



38
39
40
# File 'lib/ephem/segments/segment_group.rb', line 38

def clear_data
  @segments.each(&:clear_data)
end

#to_sObject



42
43
44
# File 'lib/ephem/segments/segment_group.rb', line 42

def to_s
  @segments.join("\n")
end