Class: Tdms::StringChannelEnumerator
- Inherits:
-
Object
- Object
- Tdms::StringChannelEnumerator
- Includes:
- Enumerable
- Defined in:
- lib/tdms/channel.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.
57 58 59 60 61 62 |
# File 'lib/tdms/channel.rb', line 57 def initialize(channel) @channel = channel @index_pos = @channel.raw_data_pos @data_pos = @index_pos + (4 * @channel.num_values) end |
Instance Method Details
#[](i) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/tdms/channel.rb', line 86 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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/tdms/channel.rb', line 68 def each data_pos = @data_pos 0.upto(size - 1) do |i| index_pos = @index_pos + (4 * i) @channel.file.seek index_pos next_data_pos = @data_pos + @channel.file.read_u32 length = next_data_pos - data_pos @channel.file.seek data_pos yield @channel.file.read(length) data_pos = next_data_pos end end |
#size ⇒ Object
64 65 66 |
# File 'lib/tdms/channel.rb', line 64 def size @size ||= @channel.num_values end |