Add #from_proforma_xml to exercise (only meta data import)

- method only considers title and description for now
- sets up relation to execution environment with id 1, just to pass
  validation for now

(leoselig/codeocean#1)
This commit is contained in:
leo.selig
2016-02-12 11:01:24 +01:00
parent 5a190c0c79
commit 943355d9c7
3 changed files with 11 additions and 0 deletions

View File

@ -1,3 +1,4 @@
require 'nokogiri'
require File.expand_path('../../../lib/active_model/validations/boolean_presence_validator', __FILE__)
class Exercise < ActiveRecord::Base
@ -105,6 +106,14 @@ class Exercise < ActiveRecord::Base
exercise
end
def from_proforma_xml(xml_string)
# how to extract the proforma functionality into a different module in rails?
xml = Nokogiri::XML(xml_string)
self.title = xml.xpath('/root/p:task/p:meta-data/p:title/text()')[0].content
self.description = xml.xpath('/root/p:task/p:description/text()')[0].content,
self.execution_environment_id = 1
end
def generate_token
self.token ||= SecureRandom.hex(4)
end