class YamlVault::KeyParser
Public Class Methods
parse(str)
click to toggle source
# File lib/yaml_vault/key_parser.rb, line 7 def self.parse(str) new.parse(str) end
Public Instance Methods
parse(str)
click to toggle source
# File lib/yaml_vault/key_parser.rb, line 11 def parse(str) s = StringScanner.new(str) path = [] until s.eos? if token = s.scan(/'(.*?)'/) path << s[1] elsif token = s.scan(/"(.*?)"/) path << s[1] elsif token = s.scan(%r{/(.*?)/}) path << Regexp.new(s[1]) elsif token = s.scan(/\[(\d+)\]/) path << s[1].to_i elsif token = s.scan(/:([^\.]+)/) path << s[1].to_sym elsif token = s.scan(/\./) # noop elsif token = s.scan(/[^\.]*/) path << token end end raise InvalidPathFormat.new("`$` must be at first") unless path.first == "$" path end