From f15edc09f338b410fb4e1d4c222515d1233a9e81 Mon Sep 17 00:00:00 2001 From: rautenberg Date: Wed, 14 Sep 2016 14:19:10 +0200 Subject: Add method chang_attributes to edit attributes of a tags 6. and 7. (1,2,3,4) --- .gitignore | 1 + README.md | 3 +++ VERSION | 2 +- lib/qmrf-report.rb | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1931eb9..2ac3ede 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.*~ *~ +tmp/ diff --git a/README.md b/README.md index 2575aec..b13b4e0 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,9 @@ report = OpenTox::QMRFReport.new # add a title report.value "QSAR_title", "My QSAR Title" +# change 6.2 'Available information for the training set' set inchi and smiles to Yes +report.change_attributes "training_set_data", {:inchi => "Yes", :smiles => "Yes"} + # add a publication to the publication catalog report.change_catalog :publications_catalog, :publications_catalog_1, {:title => "MyName M (2016) My Publication Title, QSAR News, 10, 14-22", :url => "http://myqsarnewsmag.dom"} diff --git a/VERSION b/VERSION index bcab45a..81340c7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.3 +0.0.4 diff --git a/lib/qmrf-report.rb b/lib/qmrf-report.rb index 3ec1fdd..a83bf6d 100644 --- a/lib/qmrf-report.rb +++ b/lib/qmrf-report.rb @@ -11,6 +11,7 @@ module OpenTox # require "qsar-report" # report = OpenTox::QMRFReport.new # report.value "QSAR_title", "My QSAR Title" + # report.change_attributes "training_set_data", {:inchi => "Yes", :smiles => "Yes"} # report.change_catalog :publications_catalog, :publications_catalog_1, {:title => "MyName M (2016) My Publication Title, QSAR News, 10, 14-22", :url => "http://myqsarnewsmag.dom"} # report.ref_catalog :bibliography, :publications_catalog, :publications_catalog_1 # puts report.to_xml @@ -20,6 +21,8 @@ module OpenTox SCHEMA_FILE = File.join(File.dirname(__FILE__),"template/qmrf.xsd") # QMRF XML Template file TEMPLATE_FILE = File.join(File.dirname(__FILE__),"template/qmrf.xml") + # QMRF XML tags with attributes to edit + ATTRIBUTE_TAGS = ["training_set_availability", "training_set_data", "training_set_descriptors", "dependent_var_availability", "validation_set_availability", "validation_set_data", "validation_set_descriptors", "validation_dependent_var_availability"] attr_accessor :xml, :report @@ -55,6 +58,21 @@ module OpenTox t.content end + # Set attributes of an report XML tag + # e.G.: + #@example change_attributes + # report.change_attributes "training_set_data", {:inchi => "Yes", :smiles => "Yes"} + # @param [String] key Nodename e.g.: "training_set_data" + # @param [Hash] valuehash Key-Value Hash of tag attributes to change. + # @return [Error] returns Error message if fails + def change_attributes tagname, valuehash + raise "Can not edit the attributes of tag: #{tagname}." unless ATTRIBUTE_TAGS.include? tagname + tag = @report.at_css tagname + valuehash.each do |key, value| + tag.attributes["#{key}"].value = value + end + end + # Change a catalog # @param [String] catalog Name of the catalog - One of "software_catalog", "algorithms_catalog", "descriptors_catalog", "endpoints_catalog", "publications_catalog", "authors_catalog" in QMRF v1.3 # @param [String] id Single entry node in the catalog e.G.: " -- cgit v1.2.3