Class: RubyTDMS::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_tdms/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ Document

Returns a new instance of Document.



11
12
13
14
15
16
17
18
# File 'lib/ruby_tdms/document.rb', line 11

def initialize(stream)
  @channel_aggregates = []
  @segments = []
  @stream = stream

  parse_segments
  build_aggregates
end

Instance Attribute Details

#segmentsObject (readonly)

attr_reader :segments, :channels, :file



8
9
10
# File 'lib/ruby_tdms/document.rb', line 8

def segments
  @segments
end

#streamObject (readonly)

attr_reader :segments, :channels, :file



8
9
10
# File 'lib/ruby_tdms/document.rb', line 8

def stream
  @stream
end

Instance Method Details

#as_jsonObject

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 ] } ] }



69
70
71
72
73
74
75
# 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

#channelsObject



21
22
23
# File 'lib/ruby_tdms/document.rb', line 21

def channels
  @channel_aggregates
end

#groupsObject



26
27
28
# File 'lib/ruby_tdms/document.rb', line 26

def groups
  objects.select { |object| object.is_a? Objects::Group }
end

#objectsObject



31
32
33
# File 'lib/ruby_tdms/document.rb', line 31

def objects
  segments.flat_map { |segment| segment.objects }
end

#raw_channelsArray<TDMS::Objects::Channel>

Returns The un-aggregated channel objects in the current document.

Returns:

  • (Array<TDMS::Objects::Channel>)

    The un-aggregated channel objects in the current document.



37
38
39
# File 'lib/ruby_tdms/document.rb', line 37

def raw_channels
  objects.select { |object| object.is_a? Objects::Channel }
end