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 CHANGED
@@ -2,7 +2,7 @@ class FileSort
2
2
 
3
3
  DEFAULTS = {
4
4
  sort_column: 0,
5
- column_separator: "\t",
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.round(0).to_i % 60
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-1000000.csv", {parse_as: :string, sort_column: 1}).sort!
165
+ #FileSort.new("large-file-10000000.csv", {parse_as: :int, replace_original: false}).sort!
@@ -3,7 +3,7 @@ class LargeFileGenerator
3
3
  DEFAULTS = {
4
4
  num_columns: 10,
5
5
  num_rows: 1e6.to_i,
6
- column_separator: "\t"
6
+ column_separator: ","
7
7
  }
8
8
 
9
9
  def initialize(filename, options = {})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_sort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: