Sha256: 4d988030dd68e4f5ff891e4edc9eb9cc00c5ef6726db2dc9fe8b1125230efa7e
Contents?: true
Size: 945 Bytes
Versions: 17
Compression:
Stored size: 945 Bytes
Contents
class Forgery class FileReader # Returns an array of strings containing each line in the dictionary def self.read_dictionary(dictionary) read_file(find_file(dictionary, :dictionaries)) end # Returns an array of strings containing each line in the format def self.read_format(format) read_file(find_file(format, :formats)) end protected # Reads a file while stripping leading and trailing whitespace, including # newlines def self.read_file(file) lines = [] IO.foreach(file) do |line| lines << line.strip unless line.strip == '' end lines end # Search a file in all load_paths, starting from last to first, so # last takes precedence over first. def self.find_file(name, folder) Forgery.load_paths.reverse.each do |path| file = "#{path}/#{folder}/#{name}" return file if File.exists?(file) end end end end
Version data entries
17 entries across 17 versions & 1 rubygems