RegexSeive
The RegexSieve functions in a manner similar a hash. The regex sieve
is initialized with a hash where the keys are regular expressions and
the values can be any valid Ruby object. The order of the keys
matters. When the regex sieve is accessed using the array accessor
[], it returns the first matching record.
sieve = RegexSieve.new({
/(Invincible|Born & Raised) IPA/ => 'Craft IPA',
/(Fresh Squeezed) IPA/ => 'Microbrew IPA',
/IPA/ => 'Other IPA'
})
sieve['Invincible IPA']
sieve['Awesome IPA']
sieve['Kinda Pale Ale']
By default, only the values are returned, but the key and all matching
capture groups can optionally be returned.
result_and_match = sieve['Invincible IPA', :match]
result_and_match[:match][1]
result_and_key = sieve['Invincible IPA', :regex]
result_all = sieve['Invincible IPA', :regex, :match]