class Csjparser::Reader

Public Class Methods

read(filepath) { |file| ... } click to toggle source
# File lib/csjparser/reader.rb, line 3
def self.read(filepath)
  validate(filepath)

  # Read-only to keep consistency.
  File.open(filepath, 'r') do |file|
    yield file
  end
end
validate(filepath) click to toggle source
# File lib/csjparser/reader.rb, line 12
def self.validate(filepath)
  errors = []
  errors << "File #{filepath} does not exists." unless File.exist?(filepath)
  errors << "File #{filepath} is executable. Why?" if File.executable?(filepath)
  errors << "File #{filepath} is not readable." unless File.readable?(filepath)
  raise(StandardError, errors.join("\n")) unless errors.empty?
end