Class: DeepStore::KeyParser
- Inherits:
-
Object
- Object
- DeepStore::KeyParser
- Defined in:
- lib/deep_store/key_parser.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.call(*args) ⇒ Object
3 4 5 |
# File 'lib/deep_store/key_parser.rb', line 3 def self.call(*args) new.call(*args) end |
Instance Method Details
#call(key, pattern) ⇒ Object
7 8 9 10 11 12 13 14 |
# 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 |