Parent

Forgery::FileReader

Public Class Methods

read_dictionary(dictionary) click to toggle source

Returns an array of strings containing each line in the dictionary

# File lib/forgery/file_reader.rb, line 6
def self.read_dictionary(dictionary)
  read_file(find_file(dictionary, :dictionaries))
end
read_format(format) click to toggle source

Returns an array of strings containing each line in the format

# File lib/forgery/file_reader.rb, line 11
def self.read_format(format)
  read_file(find_file(format, :formats))
end

Protected Class Methods

find_file(name, folder) click to toggle source

Search a file in all load_paths, starting from last to first, so last takes precedence over first.

# File lib/forgery/file_reader.rb, line 29
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
read_file(file) click to toggle source

Reads a file while stripping leading and trailing whitespace, including newlines

# File lib/forgery/file_reader.rb, line 19
def self.read_file(file)
  lines = []
  IO.foreach(file) do |line|
    lines << line.strip unless line.strip == ''
  end
  lines
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.