Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/motion-csv/motion-csv.rb

Instance Method Summary collapse

Instance Method Details

#depthObject



443
444
445
446
447
448
449
450
451
# File 'lib/motion-csv/motion-csv.rb', line 443

def depth
  # Thanks, StackOverflow! http://stackoverflow.com/a/10863610/814123
  b, depth = self.dup, 1
  until b==self.flatten
    depth+=1
    b=b.flatten(1)
  end
  depth
end

#to_csvObject



431
432
433
434
435
436
437
438
439
440
441
# File 'lib/motion-csv/motion-csv.rb', line 431

def to_csv
  MotionCSV.generate do |csv|
    if self.depth == 2
      self.each do |a|
        csv << a
      end
    else
      csv << self
    end
  end
end