Class: RubyTDMS::StringChannelEnumerator
- Inherits:
-
Object
- Object
- RubyTDMS::StringChannelEnumerator
- Includes:
- Enumerable
- Defined in:
- lib/ruby_tdms/string_channel_enumerator.rb
Instance Method Summary collapse
- #[](i) ⇒ Object
- #each ⇒ Object
-
#initialize(channel) ⇒ StringChannelEnumerator
constructor
A new instance of StringChannelEnumerator.
- #size ⇒ Object
Constructor Details
#initialize(channel) ⇒ StringChannelEnumerator
Returns a new instance of StringChannelEnumerator.
6 7 8 9 10 11 |
# File 'lib/ruby_tdms/string_channel_enumerator.rb', line 6 def initialize(channel) @channel = channel @index_offset = @channel.raw_data_offset @data_offset = @index_offset + (4 * @channel.value_count) end |
Instance Method Details
#[](i) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ruby_tdms/string_channel_enumerator.rb', line 38 def [](i) if (i < 0) || (i >= size) raise RangeError, 'Channel %s has a range of 0 to %d, got invalid index: %d' % [@channel.path, size - 1, i] end inject(0) do |j, value| return value if j == i j += 1 end end |
#each ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ruby_tdms/string_channel_enumerator.rb', line 19 def each data_pos = @data_offset 0.upto(size - 1) do |i| index_pos = @index_offset + (4 * i) @channel.stream.seek index_pos next_data_pos = @data_offset + @channel.stream.read_u32 length = next_data_pos - data_pos @channel.stream.seek data_pos yield @channel.stream.read(length) data_pos = next_data_pos end end |
#size ⇒ Object
14 15 16 |
# File 'lib/ruby_tdms/string_channel_enumerator.rb', line 14 def size @size ||= @channel.value_count end |