Skip to content

Commit

Permalink
fix number_of_digits
Browse files Browse the repository at this point in the history
  • Loading branch information
gipcompany committed Oct 9, 2016
1 parent 2ca4994 commit 3ce1ae2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/file_manipulator/splitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def file_name
end

def number_of_digits
@number_of_digits ||= Math.log10(File.size(file_name).to_f / config.size).ceil
@number_of_digits ||= (File.size(file_name).to_f / config.size).ceil.to_s.size
end

def output_file_name(index)
Expand Down
12 changes: 9 additions & 3 deletions spec/file_manipulator/splitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,24 @@ module FileManipulator
end

it '#number_of_digits' do
expect(splitter.send(:number_of_digits)).to eq(3)
expect(splitter.send(:number_of_digits)).to eq(4)
end

it '#output_file_name, with extension' do
index = 1
expect(splitter.send(:output_file_name, index)).to eq("file_manipulator_dummy_00#{index}.txt")
expect(splitter.send(:output_file_name, index)).to eq("file_manipulator_dummy_000#{index}.txt")
end

it '#output_file_name, with no extension' do
splitter.config.file_name = File.join(Dir.pwd, 'spec/files/dummy')
index = 1
expect(splitter.send(:output_file_name, index)).to eq("file_manipulator_dummy_00#{index}")
expect(splitter.send(:output_file_name, index)).to eq("file_manipulator_dummy_000#{index}")
end

it 'When size in config is too larger than one of the file, split file name for index 0 should suffixed with _0.' do
splitter.config.size = 10485760
index = 0
expect(splitter.send(:output_file_name, index)).to eq("file_manipulator_dummy_#{index}.txt")
end
end
end

0 comments on commit 3ce1ae2

Please sign in to comment.