Class: Ephem::IO::SummaryManager

Inherits:
Object
  • Object
show all
Defined in:
lib/ephem/io/summary_manager.rb

Overview

The SummaryManager class handles the parsing and iteration of summary records in a Double Precision Array File (DAF). It manages the extraction of summary records and their associated names, handling both little and big endian formats.

Each summary record consists of:

  • Control information (24 bytes)

  • Multiple summary entries (variable length)

  • Associated name entries in the following record

The class provides iteration capabilities over all summaries in the file, handling record chains and proper binary unpacking based on the file’s endianness.

Examples:

Basic usage

binary_reader = Ephem::IO::BinaryReader.new(file)
record_data = Ephem::IO::RecordParser
  .new
  .parse_file_record(first_record)
manager = Ephem::IO::SummaryManager.new(
  record_data: record_data,
  binary_reader: binary_reader,
  endianness: :little
)

manager.each_summary do |name, values|
  puts "Summary #{name}: #{values.inspect}"
end

Using as an enumerator

summaries = manager.each_summary.map do |name, values|
  { name: name, doubles: values[0..1], integer: values[2] }
end

Constant Summary collapse

SUMMARY_RECORD_SIZE =
1024
VALID_ENDIANNESS =
[:little, :big].freeze

Instance Method Summary collapse

Constructor Details

#initialize(record_data:, binary_reader:, endianness:) ⇒ SummaryManager

Initializes a new SummaryManager instance

Parameters:

  • record_data (RecordData)

    Data extracted from the file record, containing information about doubles count, integers count, and record chain navigation

  • binary_reader (BinaryReader)

    Reader instance for accessing binary data from the DAF file

  • endianness (Symbol)

    Endianness of the binary data, either :little or :big

Raises:

  • (ArgumentError)

    If endianness is neither :little nor :big



55
56
57
58
59
60
61
# File 'lib/ephem/io/summary_manager.rb', line 55

def initialize(record_data:, binary_reader:, endianness:)
  validate_endianness!(endianness)
  @record_data = record_data
  @binary_reader = binary_reader
  @endianness = endianness
  setup_summary_format
end

Instance Method Details

#each_summary {|name, values| ... } ⇒ Enumerator?

Iterates through each summary in the DAF file

This method traverses the chain of summary records, extracting both the summary data and associated names. It handles proper binary unpacking based on the file’s endianness and the record format specification.

If no block is given, returns an Enumerator for the summaries.

Yields:

  • (name, values)

    Yields each summary’s name and values

Yield Parameters:

  • name (String)

    The name associated with the summary

  • values (Array<Float, Integer>)

    Array containing the summary values, with doubles followed by integers according to the record format

Returns:

  • (Enumerator)

    If no block given, returns an Enumerator that will iterate over all summaries

  • (nil)

    If block given, returns nil after iteration completes



80
81
82
83
84
85
86
# File 'lib/ephem/io/summary_manager.rb', line 80

def each_summary
  return to_enum(__method__) unless block_given?

  iterate_summary_chain(@record_data.forward_record) do |name, values|
    yield name, values
  end
end