From fd76cdfba1802d3dc400ce16537ec22a0f0d5439 Mon Sep 17 00:00:00 2001 From: Aaron Lasseigne Date: Mon, 27 Apr 2020 10:34:16 -0500 Subject: [PATCH] clean up regexp --- lib/active_interaction/inputs.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/active_interaction/inputs.rb b/lib/active_interaction/inputs.rb index 00fc3b50..b735764a 100644 --- a/lib/active_interaction/inputs.rb +++ b/lib/active_interaction/inputs.rb @@ -4,7 +4,13 @@ module ActiveInteraction # Holds inputs passed to the interaction. class Inputs < DelegateClass(Hash) class << self - GROUPED_INPUT_PATTERN = /\A(.+)\((\d+)i\)\z/.freeze + # matches inputs like "key(1i)" + GROUPED_INPUT_PATTERN = / + \A + (?.+) # extracts "key" + \((?\d+)i\) # extracts "1" + \z + /x.freeze private_constant :GROUPED_INPUT_PATTERN # Checking `syscall` is the result of what appears to be a bug in Ruby. @@ -20,8 +26,8 @@ def process(inputs) inputs.stringify_keys.sort.each_with_object({}) do |(k, v), h| next if reserved?(k) - if (match = GROUPED_INPUT_PATTERN.match(k)) - assign_to_grouped_input!(h, *match.captures, v) + if (group = GROUPED_INPUT_PATTERN.match(k)) + assign_to_grouped_input!(h, group[:key], group[:index], v) else h[k.to_sym] = v end