class DmtdVbmappData::AssessmentReport

Provides for the tailoring of a VB-MAPP report from the VB-MAPP Data Server.

This class retrieves the report for the given client and performs the following operations on the report data before returning the final JSON:

The only step remaining is to format the resulting JSON into whatever output format is required (e.g. RTF, PDF, HTML, etc.).

Attributes

client[R]

The client for which the report will be generated

resolver[R]

Resolver is a block that takes a single argument, a string, which is the variable name. The result should be the value to bind to that variable.

Public Class Methods

new(opts, &resolver) click to toggle source

Initializes the receiver with the given options:

This method does not block, simply creates an accessor and returns

@option opts [Client] :client The client for which to run the report @param [method] :resolver @see resolver

# File lib/dmtd_vbmapp_data/assessment_report.rb, line 29
def initialize(opts, &resolver)
  @client = opts.fetch(:client)
  @resolver = resolver
end

Private Class Methods

end_point() click to toggle source
# File lib/dmtd_vbmapp_data/assessment_report.rb, line 92
def self.end_point
  '1/assessment_report/iep'
end

Public Instance Methods

iep() click to toggle source

Returns the JSON for the IEP report. See {datamtd.atlassian.net/wiki/pages/viewpage.action?pageId=19267590 /1/assessment_report/iep - GET} for the full format.

The following transformations are made to the server JSON:

  • The top-level 'response' node is removed

  • All variables are substituted according to resolver

  • All conditionals are evaluated

    * Only paragraphs with successful conditions are retained
    * All Condition nodes are stripped
    * All Condition_Comment nodes are stripped

@note This method will block on the first access to retrieve the

data from the server.

@note The keys in the JSON hash will be symbols and not strings.

# File lib/dmtd_vbmapp_data/assessment_report.rb, line 50
def iep
  result = retrieve_responses_json

  if result.is_a?(Array)
    result = process_report json_array:result
  end

  result
end

Private Instance Methods

process_report(json_array:) click to toggle source
# File lib/dmtd_vbmapp_data/assessment_report.rb, line 62
def process_report(json_array:)
  filtered_json = json_array.select do |para|
    keep_para = true
    condition = para[:Condition]

    unless condition.nil?
      keep_para = eval(sub_vars(condition))
    end

    keep_para
  end

  filtered_json.map do |para|
    {
      Style: para[:Style],
      Text: sub_vars(para[:Text])
    }
  end
end
retrieve_responses_json() click to toggle source
# File lib/dmtd_vbmapp_data/assessment_report.rb, line 96
def retrieve_responses_json
  response = RequestHelpers::get_authorized(end_point: AssessmentReport::end_point, params: nil, client_id: @client.id, client_code: @client.code, language: client.language)
  proc_response = RequestHelpers::process_json_response(response)
  json = proc_response[:json]
  server_response_code = proc_response[:code]

  result = json
  result = server_response_code if json.nil?

  result
end
sub_vars(sub_string) click to toggle source
# File lib/dmtd_vbmapp_data/assessment_report.rb, line 82
def sub_vars(sub_string)
  result = sub_string

  sub_string.scan(/%([a-zA-Z_][a-zA-Z0-9_]*)%/).flatten.each do |var|
    result = result.gsub("%#{var}%", resolver.call(var).to_s)
  end

  result
end