Class: ParseDecision::Plugin::PreDecisionGuideline
- Inherits:
-
Plugin
- Object
- Plugin
- ParseDecision::Plugin::PreDecisionGuideline
show all
- Defined in:
- lib/parse_decision/plugin/pre_decision_guideline.rb
Overview
####################################################################### Pre-Decision Guideline XML plugin
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Plugin
#apply_template, #apply_templates, #write_to_file
Constructor Details
Returns a new instance of PreDecisionGuideline.
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/parse_decision/plugin/pre_decision_guideline.rb', line 23
def initialize()
$LOG.debug "PreDecisionGuideline::initialize"
@fnameTemplate = "@INDEX@-@[email protected]"
@searchStrPpms = "<PARAMS><_DATA_SET"
@searchStrGdl = "<Guideline "
@searchStrGdl2 = "******Guideline*"
@searchStrGdlEnd = "<Decision GuidelineId"
@searchRulesEnd = "</Decision>"
@ppmData = ""
@ruleData = []
@openTag = "<@TAG@_DATA>\n"
@closeTag = "</@TAG@_DATA>\n"
@actualCloseTag = ""
@lineCount = 0
@chunkSize = 1000
@outfile = "PreDecision"
end
|
Instance Attribute Details
#outfile ⇒ Object
Returns the value of attribute outfile.
21
22
23
|
# File 'lib/parse_decision/plugin/pre_decision_guideline.rb', line 21
def outfile
@outfile
end
|
#ppmData ⇒ Object
Returns the value of attribute ppmData.
20
21
22
|
# File 'lib/parse_decision/plugin/pre_decision_guideline.rb', line 20
def ppmData
@ppmData
end
|
Instance Method Details
#check_for_ppms_or_rule_start(context, ln) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/parse_decision/plugin/pre_decision_guideline.rb', line 57
def check_for_ppms_or_rule_start(context, ln)
if ln.include?(@searchStrPpms)
@ppmData = ln
@ppmData.gsub!(/_DATA_SET/, "DATA_SET")
@ppmData.gsub!(/_Name/, "Name")
@ppmData.gsub!(/_Value/, "Value")
return true
end
if ln.include?(@searchStrGdl) || ln.include?(@searchStrGdl2)
context.state = :preDecisionGdl
@ruleData.clear
open_discard_element
@ruleData << ln
return true
end
return false
end
|
#close_discard_element ⇒ Object
90
91
92
93
94
95
96
97
98
|
# File 'lib/parse_decision/plugin/pre_decision_guideline.rb', line 90
def close_discard_element
if !@discarding.nil? && @discarding
@discarding = false
@ruleData << "-->\n" @ruleData << "</DISCARD_BY_PARSER>\n"
end
end
|
#close_out_rules_file(context, ln) ⇒ Object
149
150
151
152
153
154
155
156
|
# File 'lib/parse_decision/plugin/pre_decision_guideline.rb', line 149
def close_out_rules_file(context, ln)
@ruleData << ln
File.open(context.outputPath(@outfile), "a") do |f|
write_to_file(f,@ruleData)
write_to_file(f, @actualCloseTag)
end
end
|
#execute(context, ln) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/parse_decision/plugin/pre_decision_guideline.rb', line 42
def execute(context, ln)
case context.state
when :app
return check_for_ppms_or_rule_start context, ln
when :preDecisionGdl
return process_rule_data context, ln
else
return false
end end
|
#open_discard_element ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/parse_decision/plugin/pre_decision_guideline.rb', line 78
def open_discard_element
@discarding = true
@ruleData << "<DISCARD_BY_PARSER>\n"
@ruleData << "<!-- " end
|
#process_rule_data(context, ln) ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/parse_decision/plugin/pre_decision_guideline.rb', line 100
def process_rule_data(context, ln)
if ln.include?(@searchStrGdlEnd)
close_discard_element
setup_rules_file context, ln
return true
end
if ln.include?(@searchRulesEnd)
close_out_rules_file context, ln
context.state = :app
return true
end
write_rules_data context, ln
return true
end
|
#setup_rules_file(context, ln) ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/parse_decision/plugin/pre_decision_guideline.rb', line 123
def setup_rules_file(context, ln)
@ruleData << ln
gdlName = "PreDecision"
m = /\sGuidelineName="([^"]+)/.match(ln)
if m[1].length > 1
gdlName = m[1]
gdlName = context.createValidName(gdlName)
end
@outfile = apply_templates(@fnameTemplate, {"@INDEX@"=>context.indexStr, "@GDL@"=>gdlName})
@actualCloseTag = apply_template(@closeTag, "@TAG@", gdlName)
puts "Creating Gdl Rules file: #{@outfile}" if context.verbose
File.open(context.outputPath(@outfile), "w") do |f|
write_to_file(f, apply_template(@openTag, "@TAG@", gdlName))
write_to_file(f,@ppmData)
end
end
|
#write_rules_data(context, ln) ⇒ Object
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/parse_decision/plugin/pre_decision_guideline.rb', line 158
def write_rules_data(context, ln)
@ruleData << ln
@lineCount += 1
if(@lineCount > @chunkSize)
puts "Writing rule data chunk." if context.verbose
File.open(context.outputPath(@outfile), "a") do |f|
write_to_file(f,@ruleData)
end
@lineCount = 0
@ruleData.clear
end
end
|