dmtd_vbmapp_data 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62145702d8eaf8720862e4ebd8f05d5c5af9e9f0
4
- data.tar.gz: e5bbd03554809fea9e11b2e08506b3ae426dc989
3
+ metadata.gz: 9618795492ef685583687baee0ce2fbb3acdc0a1
4
+ data.tar.gz: f1349008bd09c3e3b5126de94591bfb8f4b240f2
5
5
  SHA512:
6
- metadata.gz: ea1e65ece5e633fe43f0bd943c8d71d816b058ba691f5c79eb40d74c7a87bb3d07724d17c864b461b848797f3aab1263a3ab8627468122496bd6c14d14679397
7
- data.tar.gz: 4fb9cb8b6fadab766af986123a5b4471883077466ffa7f9b1bec236792f27a2f82463bb046d385ef9bcec67ed276212cb98dbc1c13dc1a46311aa6bb0389c04f
6
+ metadata.gz: 9e488f5adcb9479715f9b30e5fa2c0b6f43bf6d560a0518aba61d8035272a9135f4a05b941dabb4049f1d8c84ad5db450e7b084db9dcfae56320f01c1f7d655a
7
+ data.tar.gz: b49afb5f8cd3b56ce191a198736ed63bfa7c3d85ba2a0e0faf1571310762e5fb8cbf758482a4ace439fbf522e203878674fc68bbbc8558db84ec7a0e675c6a5e
data/CHANGELOG.md CHANGED
@@ -4,4 +4,8 @@
4
4
 
5
5
  * Added support for setting the X-DocType via DmtdFoundation.configure document_type: 'text' || 'html'
6
6
  * Fixed a bug in the client_spec. It now specifies the correct organization id.
7
- * Changed Client.new() to allow specification of the id or code and then be used throughout the API without needing to pull it from the server.
7
+ * Changed Client.new() to allow specification of the id or code and then be used throughout the API without needing to pull it from the server.
8
+
9
+ ## 1.0.2
10
+
11
+ * Added an AssessmentReport class that simplifies the functionality of generating an IEP report
@@ -0,0 +1,111 @@
1
+ require 'dmtd_vbmapp_data/request_helpers'
2
+
3
+ module DmtdVbmappData
4
+
5
+ # Provides for the tailoring of a VB-MAPP report from the VB-MAPP Data Server.
6
+ #
7
+ # This class retrieves the report for the given client and performs the following operations on the report data
8
+ # before returning the final JSON:
9
+ #
10
+ # * All variables are substituted
11
+ # * All conditional statements are executed and only the sections that apply are returned
12
+ #
13
+ # The only step remaining is to format the resulting JSON into whatever output format is required (e.g. RTF, PDF, HTML, etc.).
14
+ class AssessmentReport
15
+
16
+ # Resolver is a block that takes a single argument, a string, which is the variable name. The result
17
+ # should be the value to bind to that variable.
18
+ attr_reader :resolver
19
+
20
+ # The client for which the report will be generated
21
+ attr_reader :client
22
+
23
+ # Initializes the receiver with the given options:
24
+ #
25
+ # This method does *not* block, simply creates an accessor and returns
26
+ #
27
+ # Params:
28
+ # +client+:: The client for which to run the report
29
+ # +resolver+:: See +resolver+ above
30
+ def initialize(opts, &resolver)
31
+ @client = opts.fetch(:client)
32
+ @resolver = resolver
33
+ end
34
+
35
+ # Returns the JSON for the IEP report (see https://datamtd.atlassian.net/wiki/pages/viewpage.action?pageId=19267590) for the
36
+ # full format.
37
+ #
38
+ # The following transformations are made to the server JSON:
39
+ #
40
+ # * The top-level 'response' node is removed
41
+ # * All variables are substituted according to +resolver+
42
+ # * All conditionals are evaluated
43
+ # * Only paragraphs with successful conditions are retained
44
+ # * All Condition nodes are stripped
45
+ # * All Condition_Comment nodes are stripped
46
+ #
47
+ # This method *will* block on the first access to retrieve the
48
+ # data from the server.
49
+ #
50
+ # Note that the keys in the JSON hash will be symbols and *not* strings.
51
+ def iep
52
+ result = retrieve_responses_json
53
+
54
+ if result.is_a?(Array)
55
+ result = process_report json_array:result
56
+ end
57
+
58
+ result
59
+ end
60
+
61
+ private
62
+
63
+ def process_report(json_array:)
64
+ filtered_json = json_array.select do |para|
65
+ keep_para = true
66
+ condition = para[:Condition]
67
+
68
+ unless condition.nil?
69
+ keep_para = eval(sub_vars(condition))
70
+ end
71
+
72
+ keep_para
73
+ end
74
+
75
+ filtered_json.map do |para|
76
+ {
77
+ Style: para[:Style],
78
+ Text: sub_vars(para[:Text])
79
+ }
80
+ end
81
+ end
82
+
83
+ def sub_vars(sub_string)
84
+ result = sub_string
85
+
86
+ sub_string.scan(/%([a-zA-Z_][a-zA-Z0-9_]*)%/).flatten.each do |var|
87
+ result = result.gsub("%#{var}%", resolver.call(var).to_s)
88
+ end
89
+
90
+ result
91
+ end
92
+
93
+ def self.end_point
94
+ '1/assessment_report/iep'
95
+ end
96
+
97
+ def retrieve_responses_json
98
+ response = RequestHelpers::get_authorized(end_point: AssessmentReport::end_point, params: nil, client_id: @client.id, client_code: @client.code)
99
+ proc_response = RequestHelpers::process_json_response(response)
100
+ json = proc_response[:json]
101
+ server_response_code = proc_response[:code]
102
+
103
+ result = json
104
+ result = server_response_code if json.nil?
105
+
106
+ result
107
+ end
108
+
109
+ end
110
+
111
+ end
@@ -1,3 +1,3 @@
1
1
  module DmtdVbmappData
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
@@ -17,6 +17,8 @@ require 'dmtd_vbmapp_data/vbmapp_area_group'
17
17
  require 'dmtd_vbmapp_data/vbmapp_area_question'
18
18
  require 'dmtd_vbmapp_data/vbmapp_area_response'
19
19
 
20
+ require 'dmtd_vbmapp_data/assessment_report'
21
+
20
22
  require 'dmtd_vbmapp_data/version'
21
23
 
22
24
  module DmtdVbmappData
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dmtd_vbmapp_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Hunt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-04 00:00:00.000000000 Z
11
+ date: 2015-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: psych
@@ -114,6 +114,7 @@ files:
114
114
  - bin/setup
115
115
  - dmtd_vbmapp_data.gemspec
116
116
  - lib/dmtd_vbmapp_data.rb
117
+ - lib/dmtd_vbmapp_data/assessment_report.rb
117
118
  - lib/dmtd_vbmapp_data/client.rb
118
119
  - lib/dmtd_vbmapp_data/guide.rb
119
120
  - lib/dmtd_vbmapp_data/guide_chapter.rb