Sha256: 29205eddcaf19a056b57f83f06b30f92091acc7c432b2563b91c282f81752e55
Contents?: true
Size: 1018 Bytes
Versions: 5
Compression:
Stored size: 1018 Bytes
Contents
require "pathname" require "json" require "yaml" module FoodTruck # Load data from a YAML file. # # @param path [String] # @return [Hash<Symbol>] def self.load_yaml(path) return FoodTruck.symbolize_keys(YAML.load_file(File.expand_path(path))) end # Load data from a JSON file. # # @param path [String] # @return [Hash<Symbol>] def self.load_json(path) return JSON.parse(File.read(File.expand_path(path)), symbolize_names: true) end # @param path [String] Path of the file to determine the extension of. # @return [String] def self.get_extension(path) file = Pathname.new(path) return file.extname.downcase end # Load data from a YAML or JSON file. # # @param path [String] # @return [Hash<Symbol>] def self.load_file(path) case Pathname.new(path).extname.downcase when ".yml", ".yaml" return self.load_yaml(path) when ".json" return self.load_json(path) else raise FoodTruck::Error "invalid file type" end end end
Version data entries
5 entries across 5 versions & 1 rubygems