diff --git a/Gemfile b/Gemfile index e77ae876..5c6bbd31 100644 --- a/Gemfile +++ b/Gemfile @@ -35,6 +35,7 @@ gem 'uglifier', '>= 1.3.0' gem 'will_paginate', '~> 3.0' gem 'tubesock' gem 'faye-websocket' +gem 'nokogiri' group :development do gem 'better_errors', platform: :ruby diff --git a/Gemfile.lock b/Gemfile.lock index 268f8596..9dda22e1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -361,6 +361,7 @@ DEPENDENCIES jquery-turbolinks kramdown newrelic_rpm + nokogiri nyan-cat-formatter pg pry diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 658a8fb5..9eabb874 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -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