Sha256: 4131dc3d085cd39c4bf39586640f9485697a17db5ad3542f71d3421471b4baac

Contents?: true

Size: 508 Bytes

Versions: 7

Compression:

Stored size: 508 Bytes

Contents

module BigFiles
  # Encapsulates a file which has a certain number of lines
  class FileWithLines
    attr_reader :filename

    def initialize(filename, file_opener: File)
      @filename = filename
      @file_opener = file_opener
    end

    def <=>(other)
      num_lines <=> other.num_lines
    end

    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
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bigfiles-0.1.3 lib/bigfiles/file_with_lines.rb
bigfiles-0.1.2 lib/bigfiles/file_with_lines.rb
bigfiles-0.1.1 lib/bigfiles/file_with_lines.rb
bigfiles-0.1.0 lib/bigfiles/file_with_lines.rb
bigfiles-0.0.3 lib/bigfiles/file_with_lines.rb
bigfiles-0.0.2 lib/bigfiles/file_with_lines.rb
bigfiles-0.0.1 lib/bigfiles/file_with_lines.rb