diff options
author | Fire Demon <firedemon@creature.cafe> | 2020-09-22 15:57:09 -0500 |
---|---|---|
committer | Fire Demon <firedemon@creature.cafe> | 2020-09-22 15:57:09 -0500 |
commit | 04e0a1fd3d43013d603092e09ac827b022cba3b9 (patch) | |
tree | 60bd63833d655ebd2987446eb97d339dd187e634 | |
parent | e6212de0474c57c6a87c35d947eeac400f68d0a7 (diff) |
Change command tag template arguments to: VARIABLE_NAME INDEX SUBSTRING_START SUBSTRING_END
-rw-r--r-- | app/lib/command_tag/processor.rb | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/app/lib/command_tag/processor.rb b/app/lib/command_tag/processor.rb index 8461e902f..6bc9a9b97 100644 --- a/app/lib/command_tag/processor.rb +++ b/app/lib/command_tag/processor.rb @@ -137,16 +137,15 @@ class CommandTag::Processor end end - index_start = to_integer(parts[1]) - index_end = to_integer(parts[2]) + index = to_integer(parts[1]) + str_start = to_integer(parts[2]) + str_end = to_integer(parts[3]) - if ['all', '[]'].include?(parts[1]) - var(name).join(separator) - elsif index_end.zero? - var(name)[index_start].presence || '' - else - var(name)[index_start..index_end].presence || '' - end + str_start, str_end = [str_end, str_start] if str_start > str_end + + value = (['all', '[]'].include?(parts[1]) ? var(name).join(separator) : var(name)[index].to_s) + + (str_end - str_start).zero? ? value : value[str_start..str_end] end end.rstrip end |