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.
6 7 8 9 |
# File 'lib/bigfiles/file_with_lines.rb', line 6 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.
4 5 6 |
# File 'lib/bigfiles/file_with_lines.rb', line 4 def filename @filename end |
Instance Method Details
#<=>(other) ⇒ Object
11 12 13 |
# File 'lib/bigfiles/file_with_lines.rb', line 11 def <=>(other) num_lines <=> other.num_lines end |
#num_lines ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/bigfiles/file_with_lines.rb', line 15 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 |