class BigFiles::FileWithLines
Encapsulates a file which has a certain number of lines
Attributes
filename[R]
Public Class Methods
new(filename, file_opener: File)
click to toggle source
# File lib/bigfiles/file_with_lines.rb, line 8 def initialize(filename, file_opener: File) @filename = filename @file_opener = file_opener end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/bigfiles/file_with_lines.rb, line 13 def <=>(other) num_lines <=> other.num_lines end
num_lines()
click to toggle source
# File lib/bigfiles/file_with_lines.rb, line 17 def num_lines num_lines = 0 @file_opener.open(filename, 'r') do |file| file.each_line do |_line| num_lines += 1 end end num_lines end