Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify slicing #1

Merged
merged 2 commits into from
Aug 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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