Skip to content

Instantly share code, notes, and snippets.

@peijiehu
Created September 9, 2014 19:30
Show Gist options
  • Save peijiehu/c735ad60e1dfd6a4976b to your computer and use it in GitHub Desktop.
Save peijiehu/c735ad60e1dfd6a4976b to your computer and use it in GitHub Desktop.
Retrieving value from yaml file
# Helper method for retrieving value from yaml file
# @param [String, String]
# keys, eg. "timeouts:implicit_wait" to retrieve value "60" from
# yml file with content:
# timeouts:
# implicit_wait: 60
def read_yml(file_name, keys)
data = Hash.new
begin
data = YAML.load_file "#{file_name}"
rescue
raise Exception, "File #{file_name} doesn't exist" unless File.exist?(file_name)
rescue
raise YAMLErrors, "Failed to load #{file_name}"
end
keys_array = keys.split(/:/)
value = data
keys_array.each do |key|
value = value[key]
end
return value
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment