file_sort 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/file_sort.rb +5 -3
- data/lib/large_file_generator.rb +1 -1
- metadata +1 -1
data/lib/file_sort.rb
CHANGED
@@ -2,7 +2,7 @@ class FileSort
|
|
2
2
|
|
3
3
|
DEFAULTS = {
|
4
4
|
sort_column: 0,
|
5
|
-
column_separator: "
|
5
|
+
column_separator: ",",
|
6
6
|
num_processes: 3,
|
7
7
|
parse_as: :int, #other options: :string
|
8
8
|
lines_per_split: 1e6,
|
@@ -12,6 +12,7 @@ class FileSort
|
|
12
12
|
|
13
13
|
def initialize(filename, options = {})
|
14
14
|
@filename = filename
|
15
|
+
raise "File '#{@filename}' doesn't exist." unless File.exists?(@filename)
|
15
16
|
@options = DEFAULTS.merge(options)
|
16
17
|
@options[:lines_per_split] = @options[:lines_per_split].to_i
|
17
18
|
|
@@ -144,10 +145,11 @@ class FileSort
|
|
144
145
|
end
|
145
146
|
|
146
147
|
def seconds_to_pretty_time(num_seconds)
|
148
|
+
num_seconds = num_seconds.round(0).to_i
|
147
149
|
hours = (num_seconds / (60**2)).to_i
|
148
150
|
minutes = ((num_seconds % (60**2)) / 60).to_i
|
149
151
|
padded_minutes = minutes < 10 ? "0#{minutes}" : minutes.to_s
|
150
|
-
seconds = num_seconds
|
152
|
+
seconds = num_seconds % 60
|
151
153
|
seconds_padded = seconds < 10 ? "0#{seconds}" : seconds.to_s
|
152
154
|
return "#{hours}:#{padded_minutes}:#{seconds_padded}"
|
153
155
|
end
|
@@ -160,4 +162,4 @@ class FileSort
|
|
160
162
|
end
|
161
163
|
|
162
164
|
#Run as
|
163
|
-
#FileSort.new("large-file-
|
165
|
+
#FileSort.new("large-file-10000000.csv", {parse_as: :int, replace_original: false}).sort!
|
data/lib/large_file_generator.rb
CHANGED