Class: Marmalade::FileReader
- Inherits:
-
Object
- Object
- Marmalade::FileReader
- Defined in:
- lib/marmalade/file_reader.rb
Overview
A class to help parsing out values from a Code Jam input file
Instance Attribute Summary collapse
-
#file_handle ⇒ Object
Returns the value of attribute file_handle.
Instance Method Summary collapse
-
#initialize(file_handle) ⇒ FileReader
constructor
A new instance of FileReader.
-
#read(assignments, options = {}) ⇒ Object
Reads the next values from the file and returns them as a hash.
Constructor Details
#initialize(file_handle) ⇒ FileReader
6 7 8 |
# File 'lib/marmalade/file_reader.rb', line 6 def initialize(file_handle) self.file_handle = file_handle end |
Instance Attribute Details
#file_handle ⇒ Object
Returns the value of attribute file_handle.
4 5 6 |
# File 'lib/marmalade/file_reader.rb', line 4 def file_handle @file_handle end |
Instance Method Details
#read(assignments, options = {}) ⇒ Object
Reads the next values from the file and returns them as a hash
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/marmalade/file_reader.rb', line 11 def read(assignments, = {}) line_count = [:count] = .dup if assignments.is_a?(Array) [:split] = true end lines = 1.upto(line_count || 1).map { read_line(file_handle, ) } lines = line_count.nil? ? lines.first : lines assign_results(assignments, lines) end |