Class: RCell

Inherits:
Object
  • Object
show all
Defined in:
datavyu_api.rb

Overview

Ruby representation of a spreadsheet cell. Generally, the two ways to get access to a cell are:

RColumn.cells to get a list of cells from a column
RColumn.new_cell to create a blank cell in a column.

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object (private)

Override method missing. Check if the method is trying to get/set an arg. If it is, define accessor method and send the method to self.



272
273
274
275
276
277
278
279
280
281
282
283
# File 'datavyu_api.rb', line 272

def method_missing(m, *args, &block)
  mn = m.to_s
  code = (mn.end_with?('=')) ? mn.chop : mn
  if (@arglist.include?(code))
    index = arglist.index(code)
    instance_eval "def #{code}; return argvals[#{index}]; end"
    instance_eval "def #{code}=(val); argvals[#{index}] = val.to_s; end"
    self.send m.to_sym, *args
  else
    super
  end
end

Instance Attribute Details

#arglistArray<String>

Note:

Use RColumn methods to modify column codes. Changing this list for the cell has no effect on the column.

Returns list of codes inherited from parent column.

Returns:

  • (Array<String>)

    list of codes inherited from parent column.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'datavyu_api.rb', line 87

class RCell
  attr_accessor :ordinal, :onset, :offset, :arglist, :argvals, :db_cell, :parent

  # @!visibility private
  # @note This method is not for general use, it is used only when creating
  #       this variable from the database in the get_column method.
  # Sets up methods that can be used to reference the arguments in
  # the cell.
  # @param argvals (required): Values of the arguments being created
  # @param arglist (required): Names of the arguments being created
  def set_args(argvals, arglist)
    @arglist = arglist
    @argvals = (argvals == '')? arglist.map{ '' } : argvals.map{ |x| x.nil?? '' : x }

    # Add getter/setter methods for each code
    arglist.each_with_index do |arg, i|
      instance_eval "def #{arg}; return argvals[#{i}]; end"
      instance_eval "def #{arg}=(val); argvals[#{i}] = val.to_s; end"
    end
  end

  # Map the specified code names to their values.
  # If no names specified, use self.arglist.
  # @note Onset, offset, and ordinal are returned as Integers; all else are Strings
  # @param codes [Array<String>] (optional): Names of codes.
  # @return [Array] Values of specified codes.
  def get_codes(*codes)
    codes = self.arglist if codes.nil? || codes.empty?
    codes.flatten!

    vals = codes.map do |cname|
      case(cname)
      when 'onset'
        self.onset
      when 'offset'
        self.offset
      when 'ordinal'
        self.ordinal
      else
        @arglist.include?(cname)? self.get_arg(cname) : raise("Failed to get the following code from cell #{self.ordinal} in column #{self.parent}: #{cname}")
      end
    end

    return vals
  end
  alias :get_args :get_codes
  alias :getArgs :get_codes

  # Defines an alias for a code
  # @!visibility private
  # @param i [Integer] index of code to change
  # @param new_name [String] new name for code
  def change_code_name(i, new_name)
    instance_eval "def #{new_name}; return argvals[#{i}]; end"
    instance_eval "def #{new_name}=(val); argvals[#{i}] = val.to_s; end"
  end
  alias :change_arg_name :change_code_name

  # Add specified code to end of arglist.
  # @param new_name [String] name of new code
  # @!visibility private
  def add_code(new_name)
    @argvals << ""
    i = argvals.length - 1
    instance_eval "def #{new_name}; return argvals[#{i}]; end"
    instance_eval "def #{new_name}=(val); argvals[#{i}] = val.to_s; end"
  end
  alias :add_arg :add_code

  # Removes code from arglist and associated value from argvals
  # @param name [String] name of code to remove
  # @return [nil]
  def remove_code(name)
    @argvals.delete(arglist.index(name))
    @arglist.delete(name)
  end
  alias :remove_arg :remove_code

  # Get value of a code
  # @param name [String] name of code
  # @return [String, Integer] value of code
  def get_code(name)
    if %w(onset offset ordinal).include?(name) || @arglist.include?(name)
      return self.send(name)
    else
      raise "Cell does not have code '#{name}'"
    end
    # return argvals[arglist.index(name)] if arglist.include?(name)
  end
  alias :get_arg :get_code

  # Changes the value of an argument in a cell.
  # @param arg [String] name of the argument to be changed
  # @param val [String, Fixnum] value to change the argument to
  # @return [nil]
  # @example
  #       trial = get_column("trial")
  #       trial.cells[0].change_code("onset", 1000)
  #       set_column(trial)
  def change_code(arg, val)
    if arg == "onset"
      val = val.to_i if val.class == String
      @onset = val
    elsif arg == "offset"
      val = val.to_i if val.class == String
      @offset = val
    elsif arg == "ordinal"
      val = val.to_i if val.class == String
      @ordinal = val
    else
      san_arg = RColumn.sanitize_codename(arg)
      if self.arglist.include?(san_arg)
        for i in 0..arglist.length-1
          if arglist[i] == arg and not arg.nil?
            argvals[i] = val.to_s
          end
        end
      else
        raise "Unable to change code '#{arg}'; no such code found."
      end
    end
  end
  alias :change_arg :change_code

  # Print ordinal, onset, offset, and values of all codes in the cell to console.
  # @param sep [String] seperator used between the arguments
  # @return [nil]
  # @example Print the first cell in the 'trial' column
  #       trial = get_column("trial")
  #       puts trial.cells[0].print_all()
  def print_all(sep="\t")
    print @ordinal.to_s + sep + @onset.to_s + sep + @offset.to_s + sep
    @arglist.each do |arg|
      t = eval "self.#{arg}"
      if t == nil
        v = ""
      else
        v = t
      end
      print v + sep
    end
  end

  # Check if self is nested temporally nested
  # @param outer_cell [RCell]: cell to check nesting against
  # @return [true, false]
  # @example
  #       trial = get_column("trial")
  #       id = get_column("id")
  #       if trial.cells[0].is_within(id.cells[0])
  #           do something
  #       end
  def is_within(outer_cell)
    return (outer_cell.onset <= @onset && outer_cell.offset >= @offset && outer_cell.onset <= @offset && outer_cell.offset >= @onset)
  end

  # Check to see if this cell encases another cell temporally
  # @param inner_cell [RCell] cell to check if contained by this cell
  # @return [true, false]
  # @example
  #       trial = get_column("trial")
  #       id = get_column("id")
  #       if id.cells[0].contains(trial.cells[0])
  #           do something
  #       end
  def contains(inner_cell)
    if (inner_cell.onset >= @onset && inner_cell.offset <= @offset && inner_cell.onset <= @offset && inner_cell.offset >= @onset)
      return true
    else
      return false
    end
  end

  # Duration of this cell (currently defined as offset minus onset)
  # @return [Integer] duration of cell in ms
  # @example
  # 	duration = myCell.duration
  def duration
    return @offset - @onset
  end

  # Override method missing.
  # Check if the method is trying to get/set an arg.
  # If it is, define accessor method and send the method to self.
  # @!visibility private
  def method_missing(m, *args, &block)
    mn = m.to_s
    code = (mn.end_with?('=')) ? mn.chop : mn
    if (@arglist.include?(code))
      index = arglist.index(code)
      instance_eval "def #{code}; return argvals[#{index}]; end"
      instance_eval "def #{code}=(val); argvals[#{index}] = val.to_s; end"
      self.send m.to_sym, *args
    else
      super
    end
  end

  # Check if given time falls within this cell's [onset, offset]
  # @param time time in milliseconds to check
  # @return [true, false] true if the given time is greater-than-or-equal to this cell's onset and less-than-or-equal to this cell's offset
  def spans(time)
    (self.onset <= time) && (self.offset >= time)
  end

  # Check if there is any intersection between this cell and given cell
  # @param cell [RCell] other cell
  # @return [true, false] true if there is any temporal overlap between self and given cell
  # @note If the onset of one cell is the offset of another, the two cells are considered to be overlapping.
  def overlaps_cell(cell)
    cell.spans(self.onset) || cell.spans(self.offset) || self.spans(cell.onset) || self.spans(cell.offset)
  end

  # Check if there is any intersection between this cell and given time range (inclusive).
  # @param [Numeric] range time range
  # @return [true, false] true if there is any temporal overlap between self and given time range
  def overlaps_range(range)
    dummy_cell = RCell.new
    dummy_cell.onset = range.first
    dummy_cell.offset = range.last
    overlaps_cell(dummy_cell)
  end

  # Gives the intersection region between self and given cell
  # @param [RCell] cell other cell
  # @return [Range] time range of intersection
  def overlapping_region(cell)
    r = Range.new([self.onset, cell.onset].max, [self.offset, cell.offset].min)
    return r
  end
end

#argvalsArray

Note:

Dangerous to modify this directly since the order of the values must match the order of the code names.

Returns list of code values

Returns:

  • (Array)

    list of code values



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'datavyu_api.rb', line 87

class RCell
  attr_accessor :ordinal, :onset, :offset, :arglist, :argvals, :db_cell, :parent

  # @!visibility private
  # @note This method is not for general use, it is used only when creating
  #       this variable from the database in the get_column method.
  # Sets up methods that can be used to reference the arguments in
  # the cell.
  # @param argvals (required): Values of the arguments being created
  # @param arglist (required): Names of the arguments being created
  def set_args(argvals, arglist)
    @arglist = arglist
    @argvals = (argvals == '')? arglist.map{ '' } : argvals.map{ |x| x.nil?? '' : x }

    # Add getter/setter methods for each code
    arglist.each_with_index do |arg, i|
      instance_eval "def #{arg}; return argvals[#{i}]; end"
      instance_eval "def #{arg}=(val); argvals[#{i}] = val.to_s; end"
    end
  end

  # Map the specified code names to their values.
  # If no names specified, use self.arglist.
  # @note Onset, offset, and ordinal are returned as Integers; all else are Strings
  # @param codes [Array<String>] (optional): Names of codes.
  # @return [Array] Values of specified codes.
  def get_codes(*codes)
    codes = self.arglist if codes.nil? || codes.empty?
    codes.flatten!

    vals = codes.map do |cname|
      case(cname)
      when 'onset'
        self.onset
      when 'offset'
        self.offset
      when 'ordinal'
        self.ordinal
      else
        @arglist.include?(cname)? self.get_arg(cname) : raise("Failed to get the following code from cell #{self.ordinal} in column #{self.parent}: #{cname}")
      end
    end

    return vals
  end
  alias :get_args :get_codes
  alias :getArgs :get_codes

  # Defines an alias for a code
  # @!visibility private
  # @param i [Integer] index of code to change
  # @param new_name [String] new name for code
  def change_code_name(i, new_name)
    instance_eval "def #{new_name}; return argvals[#{i}]; end"
    instance_eval "def #{new_name}=(val); argvals[#{i}] = val.to_s; end"
  end
  alias :change_arg_name :change_code_name

  # Add specified code to end of arglist.
  # @param new_name [String] name of new code
  # @!visibility private
  def add_code(new_name)
    @argvals << ""
    i = argvals.length - 1
    instance_eval "def #{new_name}; return argvals[#{i}]; end"
    instance_eval "def #{new_name}=(val); argvals[#{i}] = val.to_s; end"
  end
  alias :add_arg :add_code

  # Removes code from arglist and associated value from argvals
  # @param name [String] name of code to remove
  # @return [nil]
  def remove_code(name)
    @argvals.delete(arglist.index(name))
    @arglist.delete(name)
  end
  alias :remove_arg :remove_code

  # Get value of a code
  # @param name [String] name of code
  # @return [String, Integer] value of code
  def get_code(name)
    if %w(onset offset ordinal).include?(name) || @arglist.include?(name)
      return self.send(name)
    else
      raise "Cell does not have code '#{name}'"
    end
    # return argvals[arglist.index(name)] if arglist.include?(name)
  end
  alias :get_arg :get_code

  # Changes the value of an argument in a cell.
  # @param arg [String] name of the argument to be changed
  # @param val [String, Fixnum] value to change the argument to
  # @return [nil]
  # @example
  #       trial = get_column("trial")
  #       trial.cells[0].change_code("onset", 1000)
  #       set_column(trial)
  def change_code(arg, val)
    if arg == "onset"
      val = val.to_i if val.class == String
      @onset = val
    elsif arg == "offset"
      val = val.to_i if val.class == String
      @offset = val
    elsif arg == "ordinal"
      val = val.to_i if val.class == String
      @ordinal = val
    else
      san_arg = RColumn.sanitize_codename(arg)
      if self.arglist.include?(san_arg)
        for i in 0..arglist.length-1
          if arglist[i] == arg and not arg.nil?
            argvals[i] = val.to_s
          end
        end
      else
        raise "Unable to change code '#{arg}'; no such code found."
      end
    end
  end
  alias :change_arg :change_code

  # Print ordinal, onset, offset, and values of all codes in the cell to console.
  # @param sep [String] seperator used between the arguments
  # @return [nil]
  # @example Print the first cell in the 'trial' column
  #       trial = get_column("trial")
  #       puts trial.cells[0].print_all()
  def print_all(sep="\t")
    print @ordinal.to_s + sep + @onset.to_s + sep + @offset.to_s + sep
    @arglist.each do |arg|
      t = eval "self.#{arg}"
      if t == nil
        v = ""
      else
        v = t
      end
      print v + sep
    end
  end

  # Check if self is nested temporally nested
  # @param outer_cell [RCell]: cell to check nesting against
  # @return [true, false]
  # @example
  #       trial = get_column("trial")
  #       id = get_column("id")
  #       if trial.cells[0].is_within(id.cells[0])
  #           do something
  #       end
  def is_within(outer_cell)
    return (outer_cell.onset <= @onset && outer_cell.offset >= @offset && outer_cell.onset <= @offset && outer_cell.offset >= @onset)
  end

  # Check to see if this cell encases another cell temporally
  # @param inner_cell [RCell] cell to check if contained by this cell
  # @return [true, false]
  # @example
  #       trial = get_column("trial")
  #       id = get_column("id")
  #       if id.cells[0].contains(trial.cells[0])
  #           do something
  #       end
  def contains(inner_cell)
    if (inner_cell.onset >= @onset && inner_cell.offset <= @offset && inner_cell.onset <= @offset && inner_cell.offset >= @onset)
      return true
    else
      return false
    end
  end

  # Duration of this cell (currently defined as offset minus onset)
  # @return [Integer] duration of cell in ms
  # @example
  # 	duration = myCell.duration
  def duration
    return @offset - @onset
  end

  # Override method missing.
  # Check if the method is trying to get/set an arg.
  # If it is, define accessor method and send the method to self.
  # @!visibility private
  def method_missing(m, *args, &block)
    mn = m.to_s
    code = (mn.end_with?('=')) ? mn.chop : mn
    if (@arglist.include?(code))
      index = arglist.index(code)
      instance_eval "def #{code}; return argvals[#{index}]; end"
      instance_eval "def #{code}=(val); argvals[#{index}] = val.to_s; end"
      self.send m.to_sym, *args
    else
      super
    end
  end

  # Check if given time falls within this cell's [onset, offset]
  # @param time time in milliseconds to check
  # @return [true, false] true if the given time is greater-than-or-equal to this cell's onset and less-than-or-equal to this cell's offset
  def spans(time)
    (self.onset <= time) && (self.offset >= time)
  end

  # Check if there is any intersection between this cell and given cell
  # @param cell [RCell] other cell
  # @return [true, false] true if there is any temporal overlap between self and given cell
  # @note If the onset of one cell is the offset of another, the two cells are considered to be overlapping.
  def overlaps_cell(cell)
    cell.spans(self.onset) || cell.spans(self.offset) || self.spans(cell.onset) || self.spans(cell.offset)
  end

  # Check if there is any intersection between this cell and given time range (inclusive).
  # @param [Numeric] range time range
  # @return [true, false] true if there is any temporal overlap between self and given time range
  def overlaps_range(range)
    dummy_cell = RCell.new
    dummy_cell.onset = range.first
    dummy_cell.offset = range.last
    overlaps_cell(dummy_cell)
  end

  # Gives the intersection region between self and given cell
  # @param [RCell] cell other cell
  # @return [Range] time range of intersection
  def overlapping_region(cell)
    r = Range.new([self.onset, cell.onset].max, [self.offset, cell.offset].min)
    return r
  end
end

#db_cellObject

Note:

MODIFY AT OWN RISK.

Returns native Datavyu object corresponding to this cell.

Returns:

  • native Datavyu object corresponding to this cell.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'datavyu_api.rb', line 87

class RCell
  attr_accessor :ordinal, :onset, :offset, :arglist, :argvals, :db_cell, :parent

  # @!visibility private
  # @note This method is not for general use, it is used only when creating
  #       this variable from the database in the get_column method.
  # Sets up methods that can be used to reference the arguments in
  # the cell.
  # @param argvals (required): Values of the arguments being created
  # @param arglist (required): Names of the arguments being created
  def set_args(argvals, arglist)
    @arglist = arglist
    @argvals = (argvals == '')? arglist.map{ '' } : argvals.map{ |x| x.nil?? '' : x }

    # Add getter/setter methods for each code
    arglist.each_with_index do |arg, i|
      instance_eval "def #{arg}; return argvals[#{i}]; end"
      instance_eval "def #{arg}=(val); argvals[#{i}] = val.to_s; end"
    end
  end

  # Map the specified code names to their values.
  # If no names specified, use self.arglist.
  # @note Onset, offset, and ordinal are returned as Integers; all else are Strings
  # @param codes [Array<String>] (optional): Names of codes.
  # @return [Array] Values of specified codes.
  def get_codes(*codes)
    codes = self.arglist if codes.nil? || codes.empty?
    codes.flatten!

    vals = codes.map do |cname|
      case(cname)
      when 'onset'
        self.onset
      when 'offset'
        self.offset
      when 'ordinal'
        self.ordinal
      else
        @arglist.include?(cname)? self.get_arg(cname) : raise("Failed to get the following code from cell #{self.ordinal} in column #{self.parent}: #{cname}")
      end
    end

    return vals
  end
  alias :get_args :get_codes
  alias :getArgs :get_codes

  # Defines an alias for a code
  # @!visibility private
  # @param i [Integer] index of code to change
  # @param new_name [String] new name for code
  def change_code_name(i, new_name)
    instance_eval "def #{new_name}; return argvals[#{i}]; end"
    instance_eval "def #{new_name}=(val); argvals[#{i}] = val.to_s; end"
  end
  alias :change_arg_name :change_code_name

  # Add specified code to end of arglist.
  # @param new_name [String] name of new code
  # @!visibility private
  def add_code(new_name)
    @argvals << ""
    i = argvals.length - 1
    instance_eval "def #{new_name}; return argvals[#{i}]; end"
    instance_eval "def #{new_name}=(val); argvals[#{i}] = val.to_s; end"
  end
  alias :add_arg :add_code

  # Removes code from arglist and associated value from argvals
  # @param name [String] name of code to remove
  # @return [nil]
  def remove_code(name)
    @argvals.delete(arglist.index(name))
    @arglist.delete(name)
  end
  alias :remove_arg :remove_code

  # Get value of a code
  # @param name [String] name of code
  # @return [String, Integer] value of code
  def get_code(name)
    if %w(onset offset ordinal).include?(name) || @arglist.include?(name)
      return self.send(name)
    else
      raise "Cell does not have code '#{name}'"
    end
    # return argvals[arglist.index(name)] if arglist.include?(name)
  end
  alias :get_arg :get_code

  # Changes the value of an argument in a cell.
  # @param arg [String] name of the argument to be changed
  # @param val [String, Fixnum] value to change the argument to
  # @return [nil]
  # @example
  #       trial = get_column("trial")
  #       trial.cells[0].change_code("onset", 1000)
  #       set_column(trial)
  def change_code(arg, val)
    if arg == "onset"
      val = val.to_i if val.class == String
      @onset = val
    elsif arg == "offset"
      val = val.to_i if val.class == String
      @offset = val
    elsif arg == "ordinal"
      val = val.to_i if val.class == String
      @ordinal = val
    else
      san_arg = RColumn.sanitize_codename(arg)
      if self.arglist.include?(san_arg)
        for i in 0..arglist.length-1
          if arglist[i] == arg and not arg.nil?
            argvals[i] = val.to_s
          end
        end
      else
        raise "Unable to change code '#{arg}'; no such code found."
      end
    end
  end
  alias :change_arg :change_code

  # Print ordinal, onset, offset, and values of all codes in the cell to console.
  # @param sep [String] seperator used between the arguments
  # @return [nil]
  # @example Print the first cell in the 'trial' column
  #       trial = get_column("trial")
  #       puts trial.cells[0].print_all()
  def print_all(sep="\t")
    print @ordinal.to_s + sep + @onset.to_s + sep + @offset.to_s + sep
    @arglist.each do |arg|
      t = eval "self.#{arg}"
      if t == nil
        v = ""
      else
        v = t
      end
      print v + sep
    end
  end

  # Check if self is nested temporally nested
  # @param outer_cell [RCell]: cell to check nesting against
  # @return [true, false]
  # @example
  #       trial = get_column("trial")
  #       id = get_column("id")
  #       if trial.cells[0].is_within(id.cells[0])
  #           do something
  #       end
  def is_within(outer_cell)
    return (outer_cell.onset <= @onset && outer_cell.offset >= @offset && outer_cell.onset <= @offset && outer_cell.offset >= @onset)
  end

  # Check to see if this cell encases another cell temporally
  # @param inner_cell [RCell] cell to check if contained by this cell
  # @return [true, false]
  # @example
  #       trial = get_column("trial")
  #       id = get_column("id")
  #       if id.cells[0].contains(trial.cells[0])
  #           do something
  #       end
  def contains(inner_cell)
    if (inner_cell.onset >= @onset && inner_cell.offset <= @offset && inner_cell.onset <= @offset && inner_cell.offset >= @onset)
      return true
    else
      return false
    end
  end

  # Duration of this cell (currently defined as offset minus onset)
  # @return [Integer] duration of cell in ms
  # @example
  # 	duration = myCell.duration
  def duration
    return @offset - @onset
  end

  # Override method missing.
  # Check if the method is trying to get/set an arg.
  # If it is, define accessor method and send the method to self.
  # @!visibility private
  def method_missing(m, *args, &block)
    mn = m.to_s
    code = (mn.end_with?('=')) ? mn.chop : mn
    if (@arglist.include?(code))
      index = arglist.index(code)
      instance_eval "def #{code}; return argvals[#{index}]; end"
      instance_eval "def #{code}=(val); argvals[#{index}] = val.to_s; end"
      self.send m.to_sym, *args
    else
      super
    end
  end

  # Check if given time falls within this cell's [onset, offset]
  # @param time time in milliseconds to check
  # @return [true, false] true if the given time is greater-than-or-equal to this cell's onset and less-than-or-equal to this cell's offset
  def spans(time)
    (self.onset <= time) && (self.offset >= time)
  end

  # Check if there is any intersection between this cell and given cell
  # @param cell [RCell] other cell
  # @return [true, false] true if there is any temporal overlap between self and given cell
  # @note If the onset of one cell is the offset of another, the two cells are considered to be overlapping.
  def overlaps_cell(cell)
    cell.spans(self.onset) || cell.spans(self.offset) || self.spans(cell.onset) || self.spans(cell.offset)
  end

  # Check if there is any intersection between this cell and given time range (inclusive).
  # @param [Numeric] range time range
  # @return [true, false] true if there is any temporal overlap between self and given time range
  def overlaps_range(range)
    dummy_cell = RCell.new
    dummy_cell.onset = range.first
    dummy_cell.offset = range.last
    overlaps_cell(dummy_cell)
  end

  # Gives the intersection region between self and given cell
  # @param [RCell] cell other cell
  # @return [Range] time range of intersection
  def overlapping_region(cell)
    r = Range.new([self.onset, cell.onset].max, [self.offset, cell.offset].min)
    return r
  end
end

#offsetFixnum

Returns offset time of the cell in milliseconds

Returns:

  • (Fixnum)

    offset time of the cell in milliseconds



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'datavyu_api.rb', line 87

class RCell
  attr_accessor :ordinal, :onset, :offset, :arglist, :argvals, :db_cell, :parent

  # @!visibility private
  # @note This method is not for general use, it is used only when creating
  #       this variable from the database in the get_column method.
  # Sets up methods that can be used to reference the arguments in
  # the cell.
  # @param argvals (required): Values of the arguments being created
  # @param arglist (required): Names of the arguments being created
  def set_args(argvals, arglist)
    @arglist = arglist
    @argvals = (argvals == '')? arglist.map{ '' } : argvals.map{ |x| x.nil?? '' : x }

    # Add getter/setter methods for each code
    arglist.each_with_index do |arg, i|
      instance_eval "def #{arg}; return argvals[#{i}]; end"
      instance_eval "def #{arg}=(val); argvals[#{i}] = val.to_s; end"
    end
  end

  # Map the specified code names to their values.
  # If no names specified, use self.arglist.
  # @note Onset, offset, and ordinal are returned as Integers; all else are Strings
  # @param codes [Array<String>] (optional): Names of codes.
  # @return [Array] Values of specified codes.
  def get_codes(*codes)
    codes = self.arglist if codes.nil? || codes.empty?
    codes.flatten!

    vals = codes.map do |cname|
      case(cname)
      when 'onset'
        self.onset
      when 'offset'
        self.offset
      when 'ordinal'
        self.ordinal
      else
        @arglist.include?(cname)? self.get_arg(cname) : raise("Failed to get the following code from cell #{self.ordinal} in column #{self.parent}: #{cname}")
      end
    end

    return vals
  end
  alias :get_args :get_codes
  alias :getArgs :get_codes

  # Defines an alias for a code
  # @!visibility private
  # @param i [Integer] index of code to change
  # @param new_name [String] new name for code
  def change_code_name(i, new_name)
    instance_eval "def #{new_name}; return argvals[#{i}]; end"
    instance_eval "def #{new_name}=(val); argvals[#{i}] = val.to_s; end"
  end
  alias :change_arg_name :change_code_name

  # Add specified code to end of arglist.
  # @param new_name [String] name of new code
  # @!visibility private
  def add_code(new_name)
    @argvals << ""
    i = argvals.length - 1
    instance_eval "def #{new_name}; return argvals[#{i}]; end"
    instance_eval "def #{new_name}=(val); argvals[#{i}] = val.to_s; end"
  end
  alias :add_arg :add_code

  # Removes code from arglist and associated value from argvals
  # @param name [String] name of code to remove
  # @return [nil]
  def remove_code(name)
    @argvals.delete(arglist.index(name))
    @arglist.delete(name)
  end
  alias :remove_arg :remove_code

  # Get value of a code
  # @param name [String] name of code
  # @return [String, Integer] value of code
  def get_code(name)
    if %w(onset offset ordinal).include?(name) || @arglist.include?(name)
      return self.send(name)
    else
      raise "Cell does not have code '#{name}'"
    end
    # return argvals[arglist.index(name)] if arglist.include?(name)
  end
  alias :get_arg :get_code

  # Changes the value of an argument in a cell.
  # @param arg [String] name of the argument to be changed
  # @param val [String, Fixnum] value to change the argument to
  # @return [nil]
  # @example
  #       trial = get_column("trial")
  #       trial.cells[0].change_code("onset", 1000)
  #       set_column(trial)
  def change_code(arg, val)
    if arg == "onset"
      val = val.to_i if val.class == String
      @onset = val
    elsif arg == "offset"
      val = val.to_i if val.class == String
      @offset = val
    elsif arg == "ordinal"
      val = val.to_i if val.class == String
      @ordinal = val
    else
      san_arg = RColumn.sanitize_codename(arg)
      if self.arglist.include?(san_arg)
        for i in 0..arglist.length-1
          if arglist[i] == arg and not arg.nil?
            argvals[i] = val.to_s
          end
        end
      else
        raise "Unable to change code '#{arg}'; no such code found."
      end
    end
  end
  alias :change_arg :change_code

  # Print ordinal, onset, offset, and values of all codes in the cell to console.
  # @param sep [String] seperator used between the arguments
  # @return [nil]
  # @example Print the first cell in the 'trial' column
  #       trial = get_column("trial")
  #       puts trial.cells[0].print_all()
  def print_all(sep="\t")
    print @ordinal.to_s + sep + @onset.to_s + sep + @offset.to_s + sep
    @arglist.each do |arg|
      t = eval "self.#{arg}"
      if t == nil
        v = ""
      else
        v = t
      end
      print v + sep
    end
  end

  # Check if self is nested temporally nested
  # @param outer_cell [RCell]: cell to check nesting against
  # @return [true, false]
  # @example
  #       trial = get_column("trial")
  #       id = get_column("id")
  #       if trial.cells[0].is_within(id.cells[0])
  #           do something
  #       end
  def is_within(outer_cell)
    return (outer_cell.onset <= @onset && outer_cell.offset >= @offset && outer_cell.onset <= @offset && outer_cell.offset >= @onset)
  end

  # Check to see if this cell encases another cell temporally
  # @param inner_cell [RCell] cell to check if contained by this cell
  # @return [true, false]
  # @example
  #       trial = get_column("trial")
  #       id = get_column("id")
  #       if id.cells[0].contains(trial.cells[0])
  #           do something
  #       end
  def contains(inner_cell)
    if (inner_cell.onset >= @onset && inner_cell.offset <= @offset && inner_cell.onset <= @offset && inner_cell.offset >= @onset)
      return true
    else
      return false
    end
  end

  # Duration of this cell (currently defined as offset minus onset)
  # @return [Integer] duration of cell in ms
  # @example
  # 	duration = myCell.duration
  def duration
    return @offset - @onset
  end

  # Override method missing.
  # Check if the method is trying to get/set an arg.
  # If it is, define accessor method and send the method to self.
  # @!visibility private
  def method_missing(m, *args, &block)
    mn = m.to_s
    code = (mn.end_with?('=')) ? mn.chop : mn
    if (@arglist.include?(code))
      index = arglist.index(code)
      instance_eval "def #{code}; return argvals[#{index}]; end"
      instance_eval "def #{code}=(val); argvals[#{index}] = val.to_s; end"
      self.send m.to_sym, *args
    else
      super
    end
  end

  # Check if given time falls within this cell's [onset, offset]
  # @param time time in milliseconds to check
  # @return [true, false] true if the given time is greater-than-or-equal to this cell's onset and less-than-or-equal to this cell's offset
  def spans(time)
    (self.onset <= time) && (self.offset >= time)
  end

  # Check if there is any intersection between this cell and given cell
  # @param cell [RCell] other cell
  # @return [true, false] true if there is any temporal overlap between self and given cell
  # @note If the onset of one cell is the offset of another, the two cells are considered to be overlapping.
  def overlaps_cell(cell)
    cell.spans(self.onset) || cell.spans(self.offset) || self.spans(cell.onset) || self.spans(cell.offset)
  end

  # Check if there is any intersection between this cell and given time range (inclusive).
  # @param [Numeric] range time range
  # @return [true, false] true if there is any temporal overlap between self and given time range
  def overlaps_range(range)
    dummy_cell = RCell.new
    dummy_cell.onset = range.first
    dummy_cell.offset = range.last
    overlaps_cell(dummy_cell)
  end

  # Gives the intersection region between self and given cell
  # @param [RCell] cell other cell
  # @return [Range] time range of intersection
  def overlapping_region(cell)
    r = Range.new([self.onset, cell.onset].max, [self.offset, cell.offset].min)
    return r
  end
end

#onsetFixnum

Returns onset time of the cell in milliseconds

Returns:

  • (Fixnum)

    onset time of the cell in milliseconds



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'datavyu_api.rb', line 87

class RCell
  attr_accessor :ordinal, :onset, :offset, :arglist, :argvals, :db_cell, :parent

  # @!visibility private
  # @note This method is not for general use, it is used only when creating
  #       this variable from the database in the get_column method.
  # Sets up methods that can be used to reference the arguments in
  # the cell.
  # @param argvals (required): Values of the arguments being created
  # @param arglist (required): Names of the arguments being created
  def set_args(argvals, arglist)
    @arglist = arglist
    @argvals = (argvals == '')? arglist.map{ '' } : argvals.map{ |x| x.nil?? '' : x }

    # Add getter/setter methods for each code
    arglist.each_with_index do |arg, i|
      instance_eval "def #{arg}; return argvals[#{i}]; end"
      instance_eval "def #{arg}=(val); argvals[#{i}] = val.to_s; end"
    end
  end

  # Map the specified code names to their values.
  # If no names specified, use self.arglist.
  # @note Onset, offset, and ordinal are returned as Integers; all else are Strings
  # @param codes [Array<String>] (optional): Names of codes.
  # @return [Array] Values of specified codes.
  def get_codes(*codes)
    codes = self.arglist if codes.nil? || codes.empty?
    codes.flatten!

    vals = codes.map do |cname|
      case(cname)
      when 'onset'
        self.onset
      when 'offset'
        self.offset
      when 'ordinal'
        self.ordinal
      else
        @arglist.include?(cname)? self.get_arg(cname) : raise("Failed to get the following code from cell #{self.ordinal} in column #{self.parent}: #{cname}")
      end
    end

    return vals
  end
  alias :get_args :get_codes
  alias :getArgs :get_codes

  # Defines an alias for a code
  # @!visibility private
  # @param i [Integer] index of code to change
  # @param new_name [String] new name for code
  def change_code_name(i, new_name)
    instance_eval "def #{new_name}; return argvals[#{i}]; end"
    instance_eval "def #{new_name}=(val); argvals[#{i}] = val.to_s; end"
  end
  alias :change_arg_name :change_code_name

  # Add specified code to end of arglist.
  # @param new_name [String] name of new code
  # @!visibility private
  def add_code(new_name)
    @argvals << ""
    i = argvals.length - 1
    instance_eval "def #{new_name}; return argvals[#{i}]; end"
    instance_eval "def #{new_name}=(val); argvals[#{i}] = val.to_s; end"
  end
  alias :add_arg :add_code

  # Removes code from arglist and associated value from argvals
  # @param name [String] name of code to remove
  # @return [nil]
  def remove_code(name)
    @argvals.delete(arglist.index(name))
    @arglist.delete(name)
  end
  alias :remove_arg :remove_code

  # Get value of a code
  # @param name [String] name of code
  # @return [String, Integer] value of code
  def get_code(name)
    if %w(onset offset ordinal).include?(name) || @arglist.include?(name)
      return self.send(name)
    else
      raise "Cell does not have code '#{name}'"
    end
    # return argvals[arglist.index(name)] if arglist.include?(name)
  end
  alias :get_arg :get_code

  # Changes the value of an argument in a cell.
  # @param arg [String] name of the argument to be changed
  # @param val [String, Fixnum] value to change the argument to
  # @return [nil]
  # @example
  #       trial = get_column("trial")
  #       trial.cells[0].change_code("onset", 1000)
  #       set_column(trial)
  def change_code(arg, val)
    if arg == "onset"
      val = val.to_i if val.class == String
      @onset = val
    elsif arg == "offset"
      val = val.to_i if val.class == String
      @offset = val
    elsif arg == "ordinal"
      val = val.to_i if val.class == String
      @ordinal = val
    else
      san_arg = RColumn.sanitize_codename(arg)
      if self.arglist.include?(san_arg)
        for i in 0..arglist.length-1
          if arglist[i] == arg and not arg.nil?
            argvals[i] = val.to_s
          end
        end
      else
        raise "Unable to change code '#{arg}'; no such code found."
      end
    end
  end
  alias :change_arg :change_code

  # Print ordinal, onset, offset, and values of all codes in the cell to console.
  # @param sep [String] seperator used between the arguments
  # @return [nil]
  # @example Print the first cell in the 'trial' column
  #       trial = get_column("trial")
  #       puts trial.cells[0].print_all()
  def print_all(sep="\t")
    print @ordinal.to_s + sep + @onset.to_s + sep + @offset.to_s + sep
    @arglist.each do |arg|
      t = eval "self.#{arg}"
      if t == nil
        v = ""
      else
        v = t
      end
      print v + sep
    end
  end

  # Check if self is nested temporally nested
  # @param outer_cell [RCell]: cell to check nesting against
  # @return [true, false]
  # @example
  #       trial = get_column("trial")
  #       id = get_column("id")
  #       if trial.cells[0].is_within(id.cells[0])
  #           do something
  #       end
  def is_within(outer_cell)
    return (outer_cell.onset <= @onset && outer_cell.offset >= @offset && outer_cell.onset <= @offset && outer_cell.offset >= @onset)
  end

  # Check to see if this cell encases another cell temporally
  # @param inner_cell [RCell] cell to check if contained by this cell
  # @return [true, false]
  # @example
  #       trial = get_column("trial")
  #       id = get_column("id")
  #       if id.cells[0].contains(trial.cells[0])
  #           do something
  #       end
  def contains(inner_cell)
    if (inner_cell.onset >= @onset && inner_cell.offset <= @offset && inner_cell.onset <= @offset && inner_cell.offset >= @onset)
      return true
    else
      return false
    end
  end

  # Duration of this cell (currently defined as offset minus onset)
  # @return [Integer] duration of cell in ms
  # @example
  # 	duration = myCell.duration
  def duration
    return @offset - @onset
  end

  # Override method missing.
  # Check if the method is trying to get/set an arg.
  # If it is, define accessor method and send the method to self.
  # @!visibility private
  def method_missing(m, *args, &block)
    mn = m.to_s
    code = (mn.end_with?('=')) ? mn.chop : mn
    if (@arglist.include?(code))
      index = arglist.index(code)
      instance_eval "def #{code}; return argvals[#{index}]; end"
      instance_eval "def #{code}=(val); argvals[#{index}] = val.to_s; end"
      self.send m.to_sym, *args
    else
      super
    end
  end

  # Check if given time falls within this cell's [onset, offset]
  # @param time time in milliseconds to check
  # @return [true, false] true if the given time is greater-than-or-equal to this cell's onset and less-than-or-equal to this cell's offset
  def spans(time)
    (self.onset <= time) && (self.offset >= time)
  end

  # Check if there is any intersection between this cell and given cell
  # @param cell [RCell] other cell
  # @return [true, false] true if there is any temporal overlap between self and given cell
  # @note If the onset of one cell is the offset of another, the two cells are considered to be overlapping.
  def overlaps_cell(cell)
    cell.spans(self.onset) || cell.spans(self.offset) || self.spans(cell.onset) || self.spans(cell.offset)
  end

  # Check if there is any intersection between this cell and given time range (inclusive).
  # @param [Numeric] range time range
  # @return [true, false] true if there is any temporal overlap between self and given time range
  def overlaps_range(range)
    dummy_cell = RCell.new
    dummy_cell.onset = range.first
    dummy_cell.offset = range.last
    overlaps_cell(dummy_cell)
  end

  # Gives the intersection region between self and given cell
  # @param [RCell] cell other cell
  # @return [Range] time range of intersection
  def overlapping_region(cell)
    r = Range.new([self.onset, cell.onset].max, [self.offset, cell.offset].min)
    return r
  end
end

#ordinalFixnum

Note:

Prone to change after saving the column to Datavyu.

Returns ordinal number of the cell

Returns:

  • (Fixnum)

    ordinal number of the cell



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'datavyu_api.rb', line 87

class RCell
  attr_accessor :ordinal, :onset, :offset, :arglist, :argvals, :db_cell, :parent

  # @!visibility private
  # @note This method is not for general use, it is used only when creating
  #       this variable from the database in the get_column method.
  # Sets up methods that can be used to reference the arguments in
  # the cell.
  # @param argvals (required): Values of the arguments being created
  # @param arglist (required): Names of the arguments being created
  def set_args(argvals, arglist)
    @arglist = arglist
    @argvals = (argvals == '')? arglist.map{ '' } : argvals.map{ |x| x.nil?? '' : x }

    # Add getter/setter methods for each code
    arglist.each_with_index do |arg, i|
      instance_eval "def #{arg}; return argvals[#{i}]; end"
      instance_eval "def #{arg}=(val); argvals[#{i}] = val.to_s; end"
    end
  end

  # Map the specified code names to their values.
  # If no names specified, use self.arglist.
  # @note Onset, offset, and ordinal are returned as Integers; all else are Strings
  # @param codes [Array<String>] (optional): Names of codes.
  # @return [Array] Values of specified codes.
  def get_codes(*codes)
    codes = self.arglist if codes.nil? || codes.empty?
    codes.flatten!

    vals = codes.map do |cname|
      case(cname)
      when 'onset'
        self.onset
      when 'offset'
        self.offset
      when 'ordinal'
        self.ordinal
      else
        @arglist.include?(cname)? self.get_arg(cname) : raise("Failed to get the following code from cell #{self.ordinal} in column #{self.parent}: #{cname}")
      end
    end

    return vals
  end
  alias :get_args :get_codes
  alias :getArgs :get_codes

  # Defines an alias for a code
  # @!visibility private
  # @param i [Integer] index of code to change
  # @param new_name [String] new name for code
  def change_code_name(i, new_name)
    instance_eval "def #{new_name}; return argvals[#{i}]; end"
    instance_eval "def #{new_name}=(val); argvals[#{i}] = val.to_s; end"
  end
  alias :change_arg_name :change_code_name

  # Add specified code to end of arglist.
  # @param new_name [String] name of new code
  # @!visibility private
  def add_code(new_name)
    @argvals << ""
    i = argvals.length - 1
    instance_eval "def #{new_name}; return argvals[#{i}]; end"
    instance_eval "def #{new_name}=(val); argvals[#{i}] = val.to_s; end"
  end
  alias :add_arg :add_code

  # Removes code from arglist and associated value from argvals
  # @param name [String] name of code to remove
  # @return [nil]
  def remove_code(name)
    @argvals.delete(arglist.index(name))
    @arglist.delete(name)
  end
  alias :remove_arg :remove_code

  # Get value of a code
  # @param name [String] name of code
  # @return [String, Integer] value of code
  def get_code(name)
    if %w(onset offset ordinal).include?(name) || @arglist.include?(name)
      return self.send(name)
    else
      raise "Cell does not have code '#{name}'"
    end
    # return argvals[arglist.index(name)] if arglist.include?(name)
  end
  alias :get_arg :get_code

  # Changes the value of an argument in a cell.
  # @param arg [String] name of the argument to be changed
  # @param val [String, Fixnum] value to change the argument to
  # @return [nil]
  # @example
  #       trial = get_column("trial")
  #       trial.cells[0].change_code("onset", 1000)
  #       set_column(trial)
  def change_code(arg, val)
    if arg == "onset"
      val = val.to_i if val.class == String
      @onset = val
    elsif arg == "offset"
      val = val.to_i if val.class == String
      @offset = val
    elsif arg == "ordinal"
      val = val.to_i if val.class == String
      @ordinal = val
    else
      san_arg = RColumn.sanitize_codename(arg)
      if self.arglist.include?(san_arg)
        for i in 0..arglist.length-1
          if arglist[i] == arg and not arg.nil?
            argvals[i] = val.to_s
          end
        end
      else
        raise "Unable to change code '#{arg}'; no such code found."
      end
    end
  end
  alias :change_arg :change_code

  # Print ordinal, onset, offset, and values of all codes in the cell to console.
  # @param sep [String] seperator used between the arguments
  # @return [nil]
  # @example Print the first cell in the 'trial' column
  #       trial = get_column("trial")
  #       puts trial.cells[0].print_all()
  def print_all(sep="\t")
    print @ordinal.to_s + sep + @onset.to_s + sep + @offset.to_s + sep
    @arglist.each do |arg|
      t = eval "self.#{arg}"
      if t == nil
        v = ""
      else
        v = t
      end
      print v + sep
    end
  end

  # Check if self is nested temporally nested
  # @param outer_cell [RCell]: cell to check nesting against
  # @return [true, false]
  # @example
  #       trial = get_column("trial")
  #       id = get_column("id")
  #       if trial.cells[0].is_within(id.cells[0])
  #           do something
  #       end
  def is_within(outer_cell)
    return (outer_cell.onset <= @onset && outer_cell.offset >= @offset && outer_cell.onset <= @offset && outer_cell.offset >= @onset)
  end

  # Check to see if this cell encases another cell temporally
  # @param inner_cell [RCell] cell to check if contained by this cell
  # @return [true, false]
  # @example
  #       trial = get_column("trial")
  #       id = get_column("id")
  #       if id.cells[0].contains(trial.cells[0])
  #           do something
  #       end
  def contains(inner_cell)
    if (inner_cell.onset >= @onset && inner_cell.offset <= @offset && inner_cell.onset <= @offset && inner_cell.offset >= @onset)
      return true
    else
      return false
    end
  end

  # Duration of this cell (currently defined as offset minus onset)
  # @return [Integer] duration of cell in ms
  # @example
  # 	duration = myCell.duration
  def duration
    return @offset - @onset
  end

  # Override method missing.
  # Check if the method is trying to get/set an arg.
  # If it is, define accessor method and send the method to self.
  # @!visibility private
  def method_missing(m, *args, &block)
    mn = m.to_s
    code = (mn.end_with?('=')) ? mn.chop : mn
    if (@arglist.include?(code))
      index = arglist.index(code)
      instance_eval "def #{code}; return argvals[#{index}]; end"
      instance_eval "def #{code}=(val); argvals[#{index}] = val.to_s; end"
      self.send m.to_sym, *args
    else
      super
    end
  end

  # Check if given time falls within this cell's [onset, offset]
  # @param time time in milliseconds to check
  # @return [true, false] true if the given time is greater-than-or-equal to this cell's onset and less-than-or-equal to this cell's offset
  def spans(time)
    (self.onset <= time) && (self.offset >= time)
  end

  # Check if there is any intersection between this cell and given cell
  # @param cell [RCell] other cell
  # @return [true, false] true if there is any temporal overlap between self and given cell
  # @note If the onset of one cell is the offset of another, the two cells are considered to be overlapping.
  def overlaps_cell(cell)
    cell.spans(self.onset) || cell.spans(self.offset) || self.spans(cell.onset) || self.spans(cell.offset)
  end

  # Check if there is any intersection between this cell and given time range (inclusive).
  # @param [Numeric] range time range
  # @return [true, false] true if there is any temporal overlap between self and given time range
  def overlaps_range(range)
    dummy_cell = RCell.new
    dummy_cell.onset = range.first
    dummy_cell.offset = range.last
    overlaps_cell(dummy_cell)
  end

  # Gives the intersection region between self and given cell
  # @param [RCell] cell other cell
  # @return [Range] time range of intersection
  def overlapping_region(cell)
    r = Range.new([self.onset, cell.onset].max, [self.offset, cell.offset].min)
    return r
  end
end

#parentRColumn

Note:

MODIFY AT OWN RISK.

Returns the column this cell belongs to

Returns:

  • (RColumn)

    the column this cell belongs to



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'datavyu_api.rb', line 87

class RCell
  attr_accessor :ordinal, :onset, :offset, :arglist, :argvals, :db_cell, :parent

  # @!visibility private
  # @note This method is not for general use, it is used only when creating
  #       this variable from the database in the get_column method.
  # Sets up methods that can be used to reference the arguments in
  # the cell.
  # @param argvals (required): Values of the arguments being created
  # @param arglist (required): Names of the arguments being created
  def set_args(argvals, arglist)
    @arglist = arglist
    @argvals = (argvals == '')? arglist.map{ '' } : argvals.map{ |x| x.nil?? '' : x }

    # Add getter/setter methods for each code
    arglist.each_with_index do |arg, i|
      instance_eval "def #{arg}; return argvals[#{i}]; end"
      instance_eval "def #{arg}=(val); argvals[#{i}] = val.to_s; end"
    end
  end

  # Map the specified code names to their values.
  # If no names specified, use self.arglist.
  # @note Onset, offset, and ordinal are returned as Integers; all else are Strings
  # @param codes [Array<String>] (optional): Names of codes.
  # @return [Array] Values of specified codes.
  def get_codes(*codes)
    codes = self.arglist if codes.nil? || codes.empty?
    codes.flatten!

    vals = codes.map do |cname|
      case(cname)
      when 'onset'
        self.onset
      when 'offset'
        self.offset
      when 'ordinal'
        self.ordinal
      else
        @arglist.include?(cname)? self.get_arg(cname) : raise("Failed to get the following code from cell #{self.ordinal} in column #{self.parent}: #{cname}")
      end
    end

    return vals
  end
  alias :get_args :get_codes
  alias :getArgs :get_codes

  # Defines an alias for a code
  # @!visibility private
  # @param i [Integer] index of code to change
  # @param new_name [String] new name for code
  def change_code_name(i, new_name)
    instance_eval "def #{new_name}; return argvals[#{i}]; end"
    instance_eval "def #{new_name}=(val); argvals[#{i}] = val.to_s; end"
  end
  alias :change_arg_name :change_code_name

  # Add specified code to end of arglist.
  # @param new_name [String] name of new code
  # @!visibility private
  def add_code(new_name)
    @argvals << ""
    i = argvals.length - 1
    instance_eval "def #{new_name}; return argvals[#{i}]; end"
    instance_eval "def #{new_name}=(val); argvals[#{i}] = val.to_s; end"
  end
  alias :add_arg :add_code

  # Removes code from arglist and associated value from argvals
  # @param name [String] name of code to remove
  # @return [nil]
  def remove_code(name)
    @argvals.delete(arglist.index(name))
    @arglist.delete(name)
  end
  alias :remove_arg :remove_code

  # Get value of a code
  # @param name [String] name of code
  # @return [String, Integer] value of code
  def get_code(name)
    if %w(onset offset ordinal).include?(name) || @arglist.include?(name)
      return self.send(name)
    else
      raise "Cell does not have code '#{name}'"
    end
    # return argvals[arglist.index(name)] if arglist.include?(name)
  end
  alias :get_arg :get_code

  # Changes the value of an argument in a cell.
  # @param arg [String] name of the argument to be changed
  # @param val [String, Fixnum] value to change the argument to
  # @return [nil]
  # @example
  #       trial = get_column("trial")
  #       trial.cells[0].change_code("onset", 1000)
  #       set_column(trial)
  def change_code(arg, val)
    if arg == "onset"
      val = val.to_i if val.class == String
      @onset = val
    elsif arg == "offset"
      val = val.to_i if val.class == String
      @offset = val
    elsif arg == "ordinal"
      val = val.to_i if val.class == String
      @ordinal = val
    else
      san_arg = RColumn.sanitize_codename(arg)
      if self.arglist.include?(san_arg)
        for i in 0..arglist.length-1
          if arglist[i] == arg and not arg.nil?
            argvals[i] = val.to_s
          end
        end
      else
        raise "Unable to change code '#{arg}'; no such code found."
      end
    end
  end
  alias :change_arg :change_code

  # Print ordinal, onset, offset, and values of all codes in the cell to console.
  # @param sep [String] seperator used between the arguments
  # @return [nil]
  # @example Print the first cell in the 'trial' column
  #       trial = get_column("trial")
  #       puts trial.cells[0].print_all()
  def print_all(sep="\t")
    print @ordinal.to_s + sep + @onset.to_s + sep + @offset.to_s + sep
    @arglist.each do |arg|
      t = eval "self.#{arg}"
      if t == nil
        v = ""
      else
        v = t
      end
      print v + sep
    end
  end

  # Check if self is nested temporally nested
  # @param outer_cell [RCell]: cell to check nesting against
  # @return [true, false]
  # @example
  #       trial = get_column("trial")
  #       id = get_column("id")
  #       if trial.cells[0].is_within(id.cells[0])
  #           do something
  #       end
  def is_within(outer_cell)
    return (outer_cell.onset <= @onset && outer_cell.offset >= @offset && outer_cell.onset <= @offset && outer_cell.offset >= @onset)
  end

  # Check to see if this cell encases another cell temporally
  # @param inner_cell [RCell] cell to check if contained by this cell
  # @return [true, false]
  # @example
  #       trial = get_column("trial")
  #       id = get_column("id")
  #       if id.cells[0].contains(trial.cells[0])
  #           do something
  #       end
  def contains(inner_cell)
    if (inner_cell.onset >= @onset && inner_cell.offset <= @offset && inner_cell.onset <= @offset && inner_cell.offset >= @onset)
      return true
    else
      return false
    end
  end

  # Duration of this cell (currently defined as offset minus onset)
  # @return [Integer] duration of cell in ms
  # @example
  # 	duration = myCell.duration
  def duration
    return @offset - @onset
  end

  # Override method missing.
  # Check if the method is trying to get/set an arg.
  # If it is, define accessor method and send the method to self.
  # @!visibility private
  def method_missing(m, *args, &block)
    mn = m.to_s
    code = (mn.end_with?('=')) ? mn.chop : mn
    if (@arglist.include?(code))
      index = arglist.index(code)
      instance_eval "def #{code}; return argvals[#{index}]; end"
      instance_eval "def #{code}=(val); argvals[#{index}] = val.to_s; end"
      self.send m.to_sym, *args
    else
      super
    end
  end

  # Check if given time falls within this cell's [onset, offset]
  # @param time time in milliseconds to check
  # @return [true, false] true if the given time is greater-than-or-equal to this cell's onset and less-than-or-equal to this cell's offset
  def spans(time)
    (self.onset <= time) && (self.offset >= time)
  end

  # Check if there is any intersection between this cell and given cell
  # @param cell [RCell] other cell
  # @return [true, false] true if there is any temporal overlap between self and given cell
  # @note If the onset of one cell is the offset of another, the two cells are considered to be overlapping.
  def overlaps_cell(cell)
    cell.spans(self.onset) || cell.spans(self.offset) || self.spans(cell.onset) || self.spans(cell.offset)
  end

  # Check if there is any intersection between this cell and given time range (inclusive).
  # @param [Numeric] range time range
  # @return [true, false] true if there is any temporal overlap between self and given time range
  def overlaps_range(range)
    dummy_cell = RCell.new
    dummy_cell.onset = range.first
    dummy_cell.offset = range.last
    overlaps_cell(dummy_cell)
  end

  # Gives the intersection region between self and given cell
  # @param [RCell] cell other cell
  # @return [Range] time range of intersection
  def overlapping_region(cell)
    r = Range.new([self.onset, cell.onset].max, [self.offset, cell.offset].min)
    return r
  end
end

Instance Method Details

#change_code(arg, val) ⇒ nil Also known as: change_arg

Changes the value of an argument in a cell.

Examples:

trial = get_column("trial")
trial.cells[0].change_code("onset", 1000)
set_column(trial)

Parameters:

  • arg (String)

    name of the argument to be changed

  • val (String, Fixnum)

    value to change the argument to

Returns:

  • (nil)


186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'datavyu_api.rb', line 186

def change_code(arg, val)
  if arg == "onset"
    val = val.to_i if val.class == String
    @onset = val
  elsif arg == "offset"
    val = val.to_i if val.class == String
    @offset = val
  elsif arg == "ordinal"
    val = val.to_i if val.class == String
    @ordinal = val
  else
    san_arg = RColumn.sanitize_codename(arg)
    if self.arglist.include?(san_arg)
      for i in 0..arglist.length-1
        if arglist[i] == arg and not arg.nil?
          argvals[i] = val.to_s
        end
      end
    else
      raise "Unable to change code '#{arg}'; no such code found."
    end
  end
end

#contains(inner_cell) ⇒ true, false

Check to see if this cell encases another cell temporally

Examples:

trial = get_column("trial")
id = get_column("id")
if id.cells[0].contains(trial.cells[0])
    do something
end

Parameters:

  • inner_cell (RCell)

    cell to check if contained by this cell

Returns:

  • (true, false)


252
253
254
255
256
257
258
# File 'datavyu_api.rb', line 252

def contains(inner_cell)
  if (inner_cell.onset >= @onset && inner_cell.offset <= @offset && inner_cell.onset <= @offset && inner_cell.offset >= @onset)
    return true
  else
    return false
  end
end

#durationInteger

Duration of this cell (currently defined as offset minus onset)

Examples:

duration = myCell.duration

Returns:

  • (Integer)

    duration of cell in ms



264
265
266
# File 'datavyu_api.rb', line 264

def duration
  return @offset - @onset
end

#get_code(name) ⇒ String, Integer Also known as: get_arg

Get value of a code

Parameters:

  • name (String)

    name of code

Returns:

  • (String, Integer)

    value of code



168
169
170
171
172
173
174
175
# File 'datavyu_api.rb', line 168

def get_code(name)
  if %w(onset offset ordinal).include?(name) || @arglist.include?(name)
    return self.send(name)
  else
    raise "Cell does not have code '#{name}'"
  end
  # return argvals[arglist.index(name)] if arglist.include?(name)
end

#get_codes(*codes) ⇒ Array Also known as: get_args, getArgs

Note:

Onset, offset, and ordinal are returned as Integers; all else are Strings

Map the specified code names to their values. If no names specified, use self.arglist.

Parameters:

  • codes (Array<String>)

    (optional): Names of codes.

Returns:

  • (Array)

    Values of specified codes.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'datavyu_api.rb', line 113

def get_codes(*codes)
  codes = self.arglist if codes.nil? || codes.empty?
  codes.flatten!

  vals = codes.map do |cname|
    case(cname)
    when 'onset'
      self.onset
    when 'offset'
      self.offset
    when 'ordinal'
      self.ordinal
    else
      @arglist.include?(cname)? self.get_arg(cname) : raise("Failed to get the following code from cell #{self.ordinal} in column #{self.parent}: #{cname}")
    end
  end

  return vals
end

#is_within(outer_cell) ⇒ true, false

Check if self is nested temporally nested

Examples:

trial = get_column("trial")
id = get_column("id")
if trial.cells[0].is_within(id.cells[0])
    do something
end

Parameters:

  • outer_cell (RCell)

    : cell to check nesting against

Returns:

  • (true, false)


239
240
241
# File 'datavyu_api.rb', line 239

def is_within(outer_cell)
  return (outer_cell.onset <= @onset && outer_cell.offset >= @offset && outer_cell.onset <= @offset && outer_cell.offset >= @onset)
end

#overlapping_region(cell) ⇒ Range

Gives the intersection region between self and given cell

Parameters:

  • cell (RCell)

    other cell

Returns:

  • (Range)

    time range of intersection



313
314
315
316
# File 'datavyu_api.rb', line 313

def overlapping_region(cell)
  r = Range.new([self.onset, cell.onset].max, [self.offset, cell.offset].min)
  return r
end

#overlaps_cell(cell) ⇒ true, false

Note:

If the onset of one cell is the offset of another, the two cells are considered to be overlapping.

Check if there is any intersection between this cell and given cell

Parameters:

  • cell (RCell)

    other cell

Returns:

  • (true, false)

    true if there is any temporal overlap between self and given cell



296
297
298
# File 'datavyu_api.rb', line 296

def overlaps_cell(cell)
  cell.spans(self.onset) || cell.spans(self.offset) || self.spans(cell.onset) || self.spans(cell.offset)
end

#overlaps_range(range) ⇒ true, false

Check if there is any intersection between this cell and given time range (inclusive).

Parameters:

  • range (Numeric)

    time range

Returns:

  • (true, false)

    true if there is any temporal overlap between self and given time range



303
304
305
306
307
308
# File 'datavyu_api.rb', line 303

def overlaps_range(range)
  dummy_cell = RCell.new
  dummy_cell.onset = range.first
  dummy_cell.offset = range.last
  overlaps_cell(dummy_cell)
end

Print ordinal, onset, offset, and values of all codes in the cell to console.

Examples:

Print the first cell in the 'trial' column

trial = get_column("trial")
puts trial.cells[0].print_all()

Parameters:

  • sep (String) (defaults to: "\t")

    seperator used between the arguments

Returns:

  • (nil)


217
218
219
220
221
222
223
224
225
226
227
228
# File 'datavyu_api.rb', line 217

def print_all(sep="\t")
  print @ordinal.to_s + sep + @onset.to_s + sep + @offset.to_s + sep
  @arglist.each do |arg|
    t = eval "self.#{arg}"
    if t == nil
      v = ""
    else
      v = t
    end
    print v + sep
  end
end

#remove_code(name) ⇒ nil Also known as: remove_arg

Removes code from arglist and associated value from argvals

Parameters:

  • name (String)

    name of code to remove

Returns:

  • (nil)


159
160
161
162
# File 'datavyu_api.rb', line 159

def remove_code(name)
  @argvals.delete(arglist.index(name))
  @arglist.delete(name)
end

#spans(time) ⇒ true, false

Check if given time falls within this cell's [onset, offset]

Parameters:

  • time

    time in milliseconds to check

Returns:

  • (true, false)

    true if the given time is greater-than-or-equal to this cell's onset and less-than-or-equal to this cell's offset



288
289
290
# File 'datavyu_api.rb', line 288

def spans(time)
  (self.onset <= time) && (self.offset >= time)
end