Class: OpenTox::QPRFReport

Inherits:
Object
  • Object
show all
Defined in:
lib/qprf-report.rb

Overview

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

Examples:

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

Constant Summary collapse

TEMPLATE_FILE =

QPRF JSON Template file

File.join(File.dirname(__FILE__),"template/qprf.json")
MD_TEMPLATE_FILE =

QPRF MarkDown Template file

File.join(File.dirname(__FILE__),"template/qprf.haml")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeQPRFReport

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


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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

Instance Attribute Details

#jsonObject

Returns the value of attribute json


27
28
29
# File 'lib/qprf-report.rb', line 27

def json
  @json
end

#reportObject

Returns the value of attribute report


27
28
29
# File 'lib/qprf-report.rb', line 27

def report
  @report
end

Instance Method Details

#open(file) ⇒ Object

Open an existing QPRF json report

Parameters:

  • file (String)

    Name of the file


31
32
33
34
# File 'lib/qprf-report.rb', line 31

def open file
  json = File.read("#{file}")
  @report = JSON.parse(json)
end

#pretty_jsonString

returns prettified JSON representation (QPRF JSON report) of report instance

Returns:

  • (String)

    returns JSON


81
82
83
# File 'lib/qprf-report.rb', line 81

def pretty_json
  JSON.pretty_generate(@report)
end

#to_htmlString

Creates a HTML representation of the QPRF report

Returns:

  • (String)

    returns HTML


87
88
89
# 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) ⇒ String

Set or Get a value in the QPRF report

Examples:

for CAS Number

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

Parameters:

  • chapter (String)

    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” …

  • value (String) (defaults to: nil)

    Value to set. If not set the function returns the current value

Returns:

  • (String)

    returns Value


64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 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