class OpenTox::QPRFReport

Class for QPRF reporting.

Provides a ruby OpenTox class to prepare an initial version of a QPRF report. The QPRF output is in QPRF version 1.1 from May 2008 @example Report

require "qsar-report"
report = OpenTox::QPRFReport.new
report.Title = "My QPRF Report"
report.Version = "1"
report.Date = Time.now.strftime("%Y/%m/%d")
report.value "1.1", "7732-18-5" # set CAS number for H²O
puts report.to_html

Constants

MD_TEMPLATE_FILE

QPRF MarkDown Template file

TEMPLATE_FILE

QPRF JSON Template file

Attributes

json[RW]
report[RW]

Public Class Methods

new() click to toggle source

Initialize a new report instance from QPRF template. With helper functions for Title, Version and Date

# File lib/qprf-report.rb, line 37
def initialize
  json = File.read(TEMPLATE_FILE)
  @report = JSON.parse(json)

  attr_hash = {self.report['singleCalculations'] => ["Title", "Version", "Date"] }
  attr_hash.each_pair do |block, attributes|
    attributes.each do |attribute|
      define_singleton_method "#{attribute}" do
        return block[attribute]
      end
      define_singleton_method "#{attribute}=" do |val=nil|
        block[attribute] = val unless val.nil?
        return block[attribute]
      end
    end
  end

end

Public Instance Methods

open(file) click to toggle source

Open an existing QPRF json report @param [String] file Name of the file

# File lib/qprf-report.rb, line 31
def open file
  json = File.read("#{file}")
  @report = JSON.parse(json)
end
pretty_json() click to toggle source

returns prettified JSON representation (QPRF JSON report) of report instance @return [String] returns JSON

# File lib/qprf-report.rb, line 81
def pretty_json
  JSON.pretty_generate(@report)
end
to_html() click to toggle source

Creates a HTML representation of the QPRF report @return [String] returns HTML

# File lib/qprf-report.rb, line 87
def to_html
  Haml::Engine.new(File.read(MD_TEMPLATE_FILE)).render @report
end
value(chapter, value=nil) click to toggle source
Set or Get a value in the QPRF report

@example for CAS Number

 report = OpenTox::QPRFReport.new
 report.value "1.1", "7732-18-5"

@param [String] chapter Name of the chapter - e.g.:  "1.1", "1.2", "1.3", "1.4", "1.5 General", "1.5 a.", "1.5 b.", "1.5 c.", "1.5 d.", "2.1" ...
@param [String] value Value to set. If not set the function returns the current value
@return [String]  returns Value
# File lib/qprf-report.rb, line 64
def value chapter, value=nil
  case chapter
  when /^1\.\d*/
    block = "1. Substance"
  when /^2\.\d*/
    block = "2. General information"
  when /^3\.\d*/
    block = "3. Prediction"
  when /^4\.\d*/
    block = "4. Adequacy (Optional)"
  end
  @report["arrayCalculations"][block]['values'][chapter][1] = value unless value.nil?
  @report["arrayCalculations"][block]['values'][chapter][1]
end