diff --git a/lib/comma_splice/line_corrector.rb b/lib/comma_splice/line_corrector.rb index 13e8540..03116e4 100644 --- a/lib/comma_splice/line_corrector.rb +++ b/lib/comma_splice/line_corrector.rb @@ -13,8 +13,8 @@ def initialize(header_line, value_line, left_bounds = 0, right_bounds = -1) @left_bounds = left_bounds @right_bounds = right_bounds - raise 'right bounds must be less than -1' unless right_bounds < 0 - raise 'left bounds must be greater than zero' unless left_bounds >= 0 + raise 'right bounds must be negative' unless right_bounds.negative? + raise 'left bounds must be not be negative' if left_bounds.negative? end def needs_correcting? @@ -35,17 +35,8 @@ def corrected # the only values that could contain an extra comma are "artist,title,albumtitle,label" # therefore our left_bounds = 4, right_bounds = -5 - values_before = if left_bounds > 0 - values[0..(left_bounds - 1)] - else - [] - end - - values_after = if right_bounds < -1 - values[(right_bounds + 1)..-1] - else - [] - end + values_before = values[0...left_bounds] + values_after = values.slice(right_bounds + 1, -(right_bounds + 1)) [values_before, corrector.correction, values_after].flatten.join(',') end