Sha256: dea8291c30a5e8913f29051e1964f110f013c96dc993cb06f3264ce1e86aa80e
Contents?: true
Size: 987 Bytes
Versions: 6
Compression:
Stored size: 987 Bytes
Contents
# Reads in a file, removes blank lines and remarks # (lines starting with '#') and then returns # an array of all the remaining lines. # def File.read_list(filepath, chomp_string='') farr = nil farr = File.read(filepath).split("\n") farr.collect! { |line| l = line.strip.chomp(chomp_string) (l.empty? or l[0,1] == '#') ? nil : l } farr.compact end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' # FIND TEST DIRECTORY paths = File.expand_path(File.dirname(__FILE__)).split('/') paths.size.downto(1) do |i| f = (paths.slice(0..i)+['test']).join('/') $TESTDIR = File.join(f,'FIXTURE') if File.directory?(f) end raise unless $TESTDIR class TC_READ_LIST < Test::Unit::TestCase def test_read_list f = File.join( $TESTDIR, 'read_list_file' ) s = File.read_list( f ) r = ['A','B','C'] assert_equal( r, s ) end end =end
Version data entries
6 entries across 6 versions & 1 rubygems