Class: BigFiles::FileWithLines
- Inherits:
-
Object
- Object
- BigFiles::FileWithLines
- Defined in:
- lib/bigfiles/file_with_lines.rb
Overview
Encapsulates a file which has a certain number of lines
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(filename, file_opener: File) ⇒ FileWithLines
constructor
A new instance of FileWithLines.
- #num_lines ⇒ Object
Constructor Details
#initialize(filename, file_opener: File) ⇒ FileWithLines
Returns a new instance of FileWithLines.
8 9 10 11 |
# File 'lib/bigfiles/file_with_lines.rb', line 8 def initialize(filename, file_opener: File) @filename = filename @file_opener = file_opener end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
6 7 8 |
# File 'lib/bigfiles/file_with_lines.rb', line 6 def filename @filename end |
Instance Method Details
#<=>(other) ⇒ Object
13 14 15 |
# File 'lib/bigfiles/file_with_lines.rb', line 13 def <=>(other) num_lines <=> other.num_lines end |
#num_lines ⇒ Object
17 18 19 20 21 22 23 24 25 |
# 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 |