Class: Parser

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

Class Method Summary collapse

Class Method Details

.make_student_with_attributes(row) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/work_together/parser.rb', line 11

def self.make_student_with_attributes(row)
  row.delete_if {|k, v| !Student.instance_methods.include?(k.to_sym)}
  Student.new.tap do |student|
    row.each do |attribute, value|
      student.public_send("#{attribute}=", value)
    end
  end
end

.parse_and_make_students(file) ⇒ Object



5
6
7
8
9
# File 'lib/work_together/parser.rb', line 5

def self.parse_and_make_students(file)
  CSV.parse(file, headers: true).each do |row|
    make_student_with_attributes(row.to_h) unless row[0] == "first_name" || row[0].nil?
  end
end