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:
1
Gemfile
1
Gemfile
@ -35,6 +35,7 @@ gem 'uglifier', '>= 1.3.0'
|
|||||||
gem 'will_paginate', '~> 3.0'
|
gem 'will_paginate', '~> 3.0'
|
||||||
gem 'tubesock'
|
gem 'tubesock'
|
||||||
gem 'faye-websocket'
|
gem 'faye-websocket'
|
||||||
|
gem 'nokogiri'
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
gem 'better_errors', platform: :ruby
|
gem 'better_errors', platform: :ruby
|
||||||
|
@ -361,6 +361,7 @@ DEPENDENCIES
|
|||||||
jquery-turbolinks
|
jquery-turbolinks
|
||||||
kramdown
|
kramdown
|
||||||
newrelic_rpm
|
newrelic_rpm
|
||||||
|
nokogiri
|
||||||
nyan-cat-formatter
|
nyan-cat-formatter
|
||||||
pg
|
pg
|
||||||
pry
|
pry
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
require 'nokogiri'
|
||||||
require File.expand_path('../../../lib/active_model/validations/boolean_presence_validator', __FILE__)
|
require File.expand_path('../../../lib/active_model/validations/boolean_presence_validator', __FILE__)
|
||||||
|
|
||||||
class Exercise < ActiveRecord::Base
|
class Exercise < ActiveRecord::Base
|
||||||
@ -105,6 +106,14 @@ class Exercise < ActiveRecord::Base
|
|||||||
exercise
|
exercise
|
||||||
end
|
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
|
def generate_token
|
||||||
self.token ||= SecureRandom.hex(4)
|
self.token ||= SecureRandom.hex(4)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user