Class: Narabi::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/narabi/parser.rb

Class Method Summary collapse

Class Method Details

.try_to_create(regexp, src) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/narabi/parser.rb', line 10

def self.try_to_create(regexp, src)
  return nil unless match = regexp.match(src)
  indexes = regexp.named_captures
  hash = {}
  regexp.names.each do |name|
    hash[name.to_sym] = match[indexes[name].first]
  end
  hash
end