class DeepStore::KeyParser
Public Class Methods
call(*args)
click to toggle source
# File lib/deep_store/key_parser.rb, line 3 def self.call(*args) new.call(*args) end
Public Instance Methods
call(key, pattern)
click to toggle source
# File lib/deep_store/key_parser.rb, line 7 def call(key, pattern) dimensions = pattern.scan(/\:(\w+)/).flatten.map(&:to_sym) parser = pattern.gsub(/\:(\w+)/) { |m| '(?<' + m[1..-1] + '>[a-zA-Z0-9\-_.]+)' } match = key.match(parser) return {} unless match Hash[dimensions.zip(match.to_a[1..-1])] end