Class: OpenTox::QPRFReport
- Inherits:
-
Object
- Object
- OpenTox::QPRFReport
- 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
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
-
#json ⇒ Object
Returns the value of attribute json.
-
#report ⇒ Object
Returns the value of attribute report.
Instance Method Summary collapse
-
#initialize ⇒ QPRFReport
constructor
Initialize a new report instance from QPRF template.
-
#open(file) ⇒ Object
Open an existing QPRF json report.
-
#pretty_json ⇒ String
returns prettified JSON representation (QPRF JSON report) of report instance.
-
#to_html ⇒ String
Creates a HTML representation of the QPRF report.
-
#value(chapter, value = nil) ⇒ String
Set or Get a value in the QPRF report.
Constructor Details
#initialize ⇒ QPRFReport
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
#json ⇒ Object
Returns the value of attribute json.
27 28 29 |
# File 'lib/qprf-report.rb', line 27 def json @json end |
#report ⇒ Object
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
31 32 33 34 |
# File 'lib/qprf-report.rb', line 31 def open file json = File.read("#{file}") @report = JSON.parse(json) end |
#pretty_json ⇒ String
returns prettified JSON representation (QPRF JSON report) of report instance
81 82 83 |
# File 'lib/qprf-report.rb', line 81 def pretty_json JSON.pretty_generate(@report) end |
#to_html ⇒ String
Creates a HTML representation of the QPRF report
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
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 |