Class: Parser
- Inherits:
-
Object
- Object
- Parser
- Defined in:
- lib/common_tools/parser.rb
Class Method Summary collapse
Class Method Details
.build_attributes(roster) ⇒ Object
3 4 5 6 |
# File 'lib/common_tools/parser.rb', line 3 def self.build_attributes(roster) attributes_string = roster.split(/\n/).reject(&:empty?).delete_at(0) attributes_array = attributes_string.split(/\n/).first.split(',').collect {|attribute| attribute.to_sym} end |
.parse_roster(roster) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/common_tools/parser.rb', line 8 def self.parse_roster(roster) attributes_array = build_attributes(roster) student_strings = roster.split(/\n/).reject(&:empty?).drop(1) array_of_student_hashes = [] array_of_students = student_strings.collect { |student_string| student_string.split(',') } array_of_students.each_with_object(attributes_array) do |student_array, attribute_hash| array_of_student_hashes << [attribute_hash, student_array].transpose.to_h end array_of_student_hashes end |