class Symian::FileInputSequence
Public Class Methods
new(args)
click to toggle source
# File lib/symian/generator.rb, line 55 def initialize(args) @file = File.open(args[:path], 'r') # throw away the first line (containing the CSV headers) @file.gets @curr_val = args[:first_value] end
Private Class Methods
close_io(file)
click to toggle source
Need to make this a class method, or the deallocation won't take place. See: www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/
# File lib/symian/generator.rb, line 83 def self.close_io(file) Proc.new do file.close end end
Public Instance Methods
next()
click to toggle source
returns nil when EOF occurs
# File lib/symian/generator.rb, line 65 def next displacement = @file.gets.try(:chomp).try(:to_f) return nil unless displacement ret = @curr_val @curr_val += displacement ret end
Private Instance Methods
setup_finalizer()
click to toggle source
After object destruction, make sure that the input file is closed or the input command process is killed.
# File lib/symian/generator.rb, line 77 def setup_finalizer ObjectSpace.define_finalizer(self, self.class.close_io(@file)) end