Class: Highlights::Parser
- Inherits:
-
Object
- Object
- Highlights::Parser
- Defined in:
- lib/highlights/parser.rb
Defined Under Namespace
Classes: MalformedCSVError
Constant Summary collapse
- NOTES_STARTING_POSITION =
8
Instance Method Summary collapse
-
#initialize(filename) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(filename) ⇒ Parser
Returns a new instance of Parser.
6 7 8 |
# File 'lib/highlights/parser.rb', line 6 def initialize(filename) @filename = filename end |
Instance Method Details
#parse ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/highlights/parser.rb', line 10 def parse table = CSV.read(@filename, liberal_parsing: true) notes = table[NOTES_STARTING_POSITION...].map do |note_row| Note.new(*note_row) end Document.new(table[1][0], table[2][0], notes) rescue StandardError => e raise MalformedCSVError.new(e.) end |