class LoadFile::Parser

Constants

ParserError

Public Class Methods

json(content) click to toggle source
# File lib/load_file/parser.rb, line 19
def self.json(content)
  if present?(content)
    JSON.parse(content)
  else
    {}
  end
rescue JSON::ParserError
  raise ParserError
end
present?(string) click to toggle source
# File lib/load_file/parser.rb, line 29
def self.present?(string)
  string && !string.empty?
end
yaml(content) click to toggle source
# File lib/load_file/parser.rb, line 9
def self.yaml(content)
  if present?(content)
    YAML.safe_load(content, [Regexp, Symbol])
  else
    {}
  end
rescue Psych::SyntaxError
  raise ParserError
end