Skip to content

Instantly share code, notes, and snippets.

@NathanielWroblewski
Created December 3, 2013 08:06
Show Gist options
  • Select an option

  • Save NathanielWroblewski/7765625 to your computer and use it in GitHub Desktop.

Select an option

Save NathanielWroblewski/7765625 to your computer and use it in GitHub Desktop.
Dan's import challenge
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
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.
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