Module: IndeStruct::Reader
Defined Under Namespace
Classes: EmptyFileError, EmptyInputError, InputError, InvalidInputError
Instance Method Summary collapse
-
#read(input) ⇒ Object
parses YAML file or string into Ruby Hash.
Instance Method Details
#read(input) ⇒ Object
parses YAML file or string into Ruby Hash
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/inde_struct/reader.rb', line 15 def read(input) raise EmptyInputError if input.is_a?(String) && input.strip.empty? raise InvalidInputError unless input.is_a?(String) or input.is_a?(File) # read to string if File input = IO.read(input) if input.is_a?(File) or File.exist?(input) raise EmptyFileError if input.strip.empty? x = YAML.load(input) raise InputError, 'YAML input did not parse to Hash' unless x.is_a?(Hash) return x end |