Skip to content

Commit

Permalink
Merge pull request #1 from AlexMooney/simplify_slicing
Browse files Browse the repository at this point in the history
Simplify slicing
  • Loading branch information
jkeen authored Aug 26, 2019
2 parents c864a4f + c7f4232 commit d734a42
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions lib/comma_splice/line_corrector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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

Expand Down

0 comments on commit d734a42

Please sign in to comment.