class RubyTDMS::Document

Attributes

segments[R]

attr_reader :segments, :channels, :file

stream[R]

attr_reader :segments, :channels, :file

Public Class Methods

new(stream) click to toggle source
# File lib/ruby_tdms/document.rb, line 11
def initialize(stream)
        @channel_aggregates = []
        @segments = []
        @stream = stream

        parse_segments
        build_aggregates
end

Public Instance Methods

as_json() click to toggle source

Returns a hash representation of the entire TDMS document, looking vaguely like: { file : [

properties: {}

],

groups : [
{
        path: '/Time Domain',
        properties: {}

}

],

channels : [
{
        path: '/Time Domain/Current Phase A',
        name: 'Current Phase A',
        properties: { 'wf_start': 2015-05-23 05:22:22 },
        values: [
                1,
                2,
                3,
                4,
                5
        ]
}

] }

# File lib/ruby_tdms/document.rb, line 69
def as_json
        {
                file: objects.find { |object| object.is_a? Objects::File }.as_json,
                groups: objects.select { |object| object.is_a? Objects::Group }.map(&:as_json),
                channels: channels.map(&:as_json)
        }
end
channels() click to toggle source
# File lib/ruby_tdms/document.rb, line 21
def channels
        @channel_aggregates
end
groups() click to toggle source
# File lib/ruby_tdms/document.rb, line 26
def groups
        objects.select { |object| object.is_a? Objects::Group }
end
objects() click to toggle source
# File lib/ruby_tdms/document.rb, line 31
def objects
        segments.flat_map { |segment| segment.objects }
end
raw_channels() click to toggle source

@return [Array<TDMS::Objects::Channel>] The un-aggregated channel objects in the current document.

# File lib/ruby_tdms/document.rb, line 37
def raw_channels
        objects.select { |object| object.is_a? Objects::Channel }
end

Protected Instance Methods

build_aggregates() click to toggle source
# File lib/ruby_tdms/document.rb, line 91
def build_aggregates
        channels_by_path =
                raw_channels.reduce({}) do |hash, channel|
                        hash[channel.path] ||= []
                        hash[channel.path] << channel
                        hash
                end

        channels_by_path.each_pair do |path, channels|
                @channel_aggregates << AggregateChannel.new(channels)
        end
end
parse_segments() click to toggle source
# File lib/ruby_tdms/document.rb, line 80
def parse_segments
        until stream.eof?
                segment = Segment.parse_stream(stream, self)
                break if segment.nil?
                #@segments << segment
                next_segment_offset = segment.meta_data_offset._?(segment.raw_data_offset) + segment.length
                stream.seek next_segment_offset
        end
end