Sha256: b769ff20b6516be379f1b4cb63ed1e31bbe7d74a552f05d2f1cee40f39c2979e

Contents?: true

Size: 539 Bytes

Versions: 4

Compression:

Stored size: 539 Bytes

Contents

# frozen_string_literal: true

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

4 entries across 4 versions & 1 rubygems

Version Path
bigfiles-0.3.0 lib/bigfiles/file_with_lines.rb
bigfiles-0.2.2 lib/bigfiles/file_with_lines.rb
bigfiles-0.2.1 lib/bigfiles/file_with_lines.rb
bigfiles-0.2.0 lib/bigfiles/file_with_lines.rb