lib/contrast/agent/assess/policy/propagator/select.rb in contrast-agent-7.5.0 vs lib/contrast/agent/assess/policy/propagator/select.rb in contrast-agent-7.6.0
- old
+ new
@@ -11,10 +11,14 @@
# Disclaimer: there may be a better way, but we're
# in a 'get it work' state. hopefully, we'll be in
# a 'get it right' state soon.
class Select
class << self
+ # @param patcher [Contrast::Agent::Assess::Patcher] the patcher
+ # @param preshift [Object] pre call state of the things.
+ # @param ret [Object] the return value of the method.
+ # @param _block [Proc] the block passed to the method.
def select_tagger patcher, preshift, ret, _block
source = preshift.object
args = preshift.args
# 'gotcha'
@@ -40,29 +44,51 @@
ret
end
private
+ # Handles the integer case for select.
+ #
+ # @param args [Array] the arguments passed to the method
+ # @param arg [Object] the first argument passed to the method
+ # @param source [String] the source string
+ # @return [Range, nil] the range to select from the source string
def handle_integer args, arg, source
length = args[1] || 1
# (void) negative range
arg += source.length if arg.negative?
arg...(arg + length)
end
+ # Handles the string case for select.
+ #
+ # @param arg [String] the first argument passed to the method
+ # @param source [String] the source string
+ # @return [Range, nil] the range to select from the source string
def handle_string arg, source
idx = source.index(arg)
idx...(idx + arg.length)
end
+ # Handles the regexp case for select.
+ #
+ # @param args [Array] the arguments passed to the method
+ # @param arg [Regexp] the first argument passed to the method
+ # @param source [String] the source string
+ # @return [Range, nil] the range to select from the source string
def handle_regexp args, arg, source
match_data = arg.match(source)
# nil has the same meaning as 0. use full match
group = args[1] || 0
match_data.begin(group)...match_data.end(group)
end
+ # Handles the range case for select.
+ #
+ # @param arg [Range] the first argument passed to the method
+ # @param source [String] the source string
+ # @return [Range, nil] the range to select from the source string
def handle_range arg, source
start = arg.begin
finish = arg.end
# (void) negative range
@@ -71,9 +97,13 @@
finish += 1 unless arg.exclude_end?
start...finish
end
+ # Determines the range to select from the source string.
+ #
+ # @param source [Object] the source string
+ # @param args [Array] the arguments passed to the method
def determine_select_range source, args
arg = args[0]
case arg
when Integer
handle_integer(args, arg, source)