Created
December 3, 2013 08:06
-
-
Save NathanielWroblewski/7765625 to your computer and use it in GitHub Desktop.
Dan's import challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Parser | |
| attr_accessor :row | |
| def initialize(row) | |
| @row = row | |
| end | |
| def question_ids | |
| row.headers.first.gsub('q', '').split(' ')[1..-1].map(&:to_i) | |
| end | |
| def user_id | |
| row.first.last.split(' ').shift.gsub('u', '').to_i | |
| end | |
| def responses | |
| row.first.last.split(' ')[1..-1].map(&:to_i) | |
| end | |
| def create_responses | |
| question_ids.each_with_index do |qid, index| | |
| Response.create( | |
| question_id: qid, | |
| user_id: user_id, | |
| response: responses[index] | |
| ) | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Response | |
| def self.create(attrs) | |
| p attrs | |
| end | |
| end |
We can make this file beautiful and searchable if this error is corrected: No tabs found in this TSV file in line 0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| id q1 q2 q3 | |
| u1 5 6 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment