Class: Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/common_tools/parser.rb

Class Method Summary collapse

Class Method Details

.build_batch(file) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/common_tools/parser.rb', line 8

def self.build_batch(file)
  headers = CSV.read(file, headers: true).headers
  Student.build_attributes(headers)
  CSV.foreach(file, headers: true).map do |row|
    make_student_attributes(row) unless row[0] == "first_name" || row[0].nil?
  end.to_json
end

.make_student_attributes(row) ⇒ Object



16
17
18
# File 'lib/common_tools/parser.rb', line 16

def self.make_student_attributes(row)
  Student.new(row.to_h)
end