Sha256: e32d7d76247dde1161d77105a92383c45bed6ee117aea1691d9d511520bb6772

Contents?: true

Size: 909 Bytes

Versions: 10

Compression:

Stored size: 909 Bytes

Contents

class File

  # Cleans up a filename to ensure it will work on filesystem.
  #
  # CREDIT: George Moschovitis

  def self.sanitize(filename)
    filename = File.basename(filename.gsub("\\", "/")) # work-around for IE
    filename.gsub!(/[^a-zA-Z0-9\.\-\+_]/,"_")
    filename = "_#{filename}" if filename =~ /^\.+$/
    filename
  end

  # Read in a file as binary data.
  #
  # CREDIT: George Moschovitis

  def self.read_binary(fname)
    open(fname, 'rb') {|f|
      return f.read
    }
  end

  # Reads in a file, removes blank lines and remarks
  # (lines starting with '#') and then returns
  # an array of all the remaining lines.
  #
  # CREDIT: Trans

  def self.read_list(filepath, chomp_string='')
    farr = nil
    farr = read(filepath).split("\n")
    farr.collect! { |line|
      l = line.strip.chomp(chomp_string)
      (l.empty? or l[0,1] == '#') ? nil : l
    }
    farr.compact
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facets-2.8.4 lib/core/facets/file/read.rb
facets-2.8.3 lib/core/facets/file/read.rb
facets-2.8.2 lib/core/facets/file/read.rb
facets-2.8.1 lib/core/facets/file/read.rb
facets-2.8.0 lib/core/facets/file/read.rb
facets-2.7.0 lib/core/facets/file/read.rb
facets-2.6.0 lib/core/facets/file/read.rb
facets-2.5.0 lib/core/facets/file/read.rb
facets-2.5.1 lib/core/facets/file/read.rb
facets-2.5.2 lib/core/facets/file/read.rb