parse_decision 0.0.5
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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/LICENSE +22 -0
- data/README.md +71 -0
- data/bin/parse_decision +126 -0
- data/lib/parse_decision/config.rb +90 -0
- data/lib/parse_decision/controller.rb +142 -0
- data/lib/parse_decision/parsedecisiontask.rb +31 -0
- data/lib/parse_decision/parser.rb +194 -0
- data/lib/parse_decision/pd_context.rb +148 -0
- data/lib/parse_decision/plugin/application.rb +48 -0
- data/lib/parse_decision/plugin/plugin.rb +56 -0
- data/lib/parse_decision/plugin/ppm_xpath.rb +70 -0
- data/lib/parse_decision/plugin/pre_decision_guideline.rb +177 -0
- data/lib/parse_decision/plugin/product.rb +176 -0
- data/lib/parse_decision/plugin/product_xpath.rb +52 -0
- data/lib/parse_decision/plugin/web_product.rb +179 -0
- data/lib/parse_decision/plugin.rb +50 -0
- data/lib/parse_decision/version.rb +5 -0
- data/lib/parse_decision.rb +59 -0
- data/parse_decision.gemspec +27 -0
- data/rakefile.rb +58 -0
- data/spec/context_spec.rb +21 -0
- data/spec/data/multiproduct.decision.txt +1481 -0
- data/spec/data/prod.decision.txt +3957 -0
- data/spec/data/reference/multiproduct/001-APP.xml +1 -0
- data/spec/data/reference/multiproduct/001-Mod-Forbear-PRODUCT.xml +357 -0
- data/spec/data/reference/multiproduct/001-Mod-Forgive-PRODUCT.xml +361 -0
- data/spec/data/reference/multiproduct/001-Mod-RateTerm-PRODUCT.xml +353 -0
- data/spec/data/reference/multiproduct/001-Mod-SAM-PRODUCT.xml +365 -0
- data/spec/data/reference/product/001-APP.xml +1 -0
- data/spec/data/reference/product/001-Validation-Rules.xml +536 -0
- data/spec/data/reference/product/002-APP.xml +1 -0
- data/spec/data/reference/product/002-FAPIILoanModification-PRODUCT.xml +1770 -0
- data/spec/data/reference/web/001-APP.xml +1 -0
- data/spec/data/reference/web/001-Product01-PRODUCT.xml +1088 -0
- data/spec/data/reference/web/002-APP.xml +1 -0
- data/spec/data/reference/web/002-Product01-PRODUCT.xml +15 -0
- data/spec/data/reference/workflow/001-APP.xml +1 -0
- data/spec/data/reference/workflow/001-WF-DataClearing-Pre-Rules.xml +37 -0
- data/spec/data/reference/workflow-2/001-APP.xml +1 -0
- data/spec/data/reference/workflow-2/001-WF-ProdSel-Post-Rules.xml +699 -0
- data/spec/data/test.rb +13 -0
- data/spec/data/validation.decision.txt +1199 -0
- data/spec/data/web.decision.txt +1128 -0
- data/spec/data/wf.decision.txt +43 -0
- data/spec/data/wf2.decision.txt +705 -0
- data/spec/parser_spec.rb +308 -0
- data/spec/plugin_app_spec.rb +40 -0
- data/spec/plugin_ppmxpath_spec.rb +74 -0
- data/spec/plugin_predecision_spec.rb +81 -0
- data/spec/plugin_product_spec.rb +117 -0
- data/spec/plugin_productxpath_spec.rb +76 -0
- data/spec/plugin_spec.rb +54 -0
- data/spec/spec_helper.rb +81 -0
- data/test/data/2.2.decision-multiple.txt +1391 -0
- data/test/data/2.2.decision.txt +1128 -0
- data/test/data/2.decision.txt +1481 -0
- data/test/plugins/test_plugin_predecisionguideline.rb +120 -0
- data/test/plugins/test_plugin_product.rb +120 -0
- data/test/test_config.rb +90 -0
- data/test/test_context.rb +103 -0
- data/test/test_parse_webdecision.rb +121 -0
- data/test/test_parser.rb +69 -0
- data/test/test_parser_parse.rb +110 -0
- metadata +225 -0
@@ -0,0 +1,176 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# File:: plugin.rb
|
3
|
+
# Purpose:: Plugin objects for ParseDecision utility
|
4
|
+
#
|
5
|
+
# Author:: Jeff McAffee 04/17/2010
|
6
|
+
# Copyright:: Copyright (c) 2010, kTech Systems LLC. All rights reserved.
|
7
|
+
# Website:: http://ktechsystems.com
|
8
|
+
##############################################################################
|
9
|
+
|
10
|
+
##############################################################################
|
11
|
+
module ParseDecision
|
12
|
+
|
13
|
+
##############################################################################
|
14
|
+
module Plugin
|
15
|
+
|
16
|
+
## #######################################################################
|
17
|
+
# Product info plugin
|
18
|
+
class Product < Plugin
|
19
|
+
attr_reader :data
|
20
|
+
|
21
|
+
def initialize()
|
22
|
+
$LOG.debug "Product::initialize"
|
23
|
+
@fnameTemplate = "@INDEX@-@PROD@-PRODUCT.xml"
|
24
|
+
@searchStr1 = "<PRODUCTS><PRODUCT"
|
25
|
+
@searchStr2 = "<PARAMS><_DATA_SET"
|
26
|
+
|
27
|
+
@ruleStartStr = "<Rules>"
|
28
|
+
@gdlStartStr = "<Decision GuidelineId"
|
29
|
+
@stopStr = "</Decision>"
|
30
|
+
|
31
|
+
@data = []
|
32
|
+
@openTag = "<@TAG@_DATA>\n"
|
33
|
+
@closeTag = "</@TAG@_DATA>\n"
|
34
|
+
@openTag = "<PRODUCT_DATA>\n"
|
35
|
+
@closeTag = "</PRODUCT_DATA>\n"
|
36
|
+
@lineCount = 0
|
37
|
+
@chunkSize = 1000
|
38
|
+
@product = ""
|
39
|
+
|
40
|
+
set_outfile( "" )
|
41
|
+
end
|
42
|
+
|
43
|
+
def set_outfile( outfile )
|
44
|
+
@outfile = outfile
|
45
|
+
end
|
46
|
+
|
47
|
+
def execute(context, ln)
|
48
|
+
#$LOG.debug "Product::execute"
|
49
|
+
|
50
|
+
case context.state
|
51
|
+
when :app
|
52
|
+
return accept_as_product_data context, ln
|
53
|
+
|
54
|
+
when :productXml
|
55
|
+
return accept_product_ppms context, ln
|
56
|
+
|
57
|
+
when :productPpms
|
58
|
+
return accept_product_rules context, ln
|
59
|
+
|
60
|
+
when :productRules
|
61
|
+
return process_product_rules context, ln
|
62
|
+
|
63
|
+
else
|
64
|
+
return false
|
65
|
+
|
66
|
+
end # case
|
67
|
+
end
|
68
|
+
|
69
|
+
def accept_as_product_data(context, ln)
|
70
|
+
if ln.include?(@searchStr1)
|
71
|
+
context.state = :productXml
|
72
|
+
@data.clear
|
73
|
+
set_outfile( "" )
|
74
|
+
|
75
|
+
# Generate the name of the output file
|
76
|
+
match = ln.match /\sName="([^"]+)/
|
77
|
+
product = "UnkProduct"
|
78
|
+
if(match && match.length > 1)
|
79
|
+
product = match[1]
|
80
|
+
end
|
81
|
+
@product = context.createValidName(product)
|
82
|
+
set_outfile( apply_templates(@fnameTemplate, {"@INDEX@"=>context.indexStr, "@PROD@"=>@product}) )
|
83
|
+
|
84
|
+
@data << ln
|
85
|
+
|
86
|
+
create_data_file context
|
87
|
+
|
88
|
+
@data.clear
|
89
|
+
return true
|
90
|
+
end
|
91
|
+
|
92
|
+
return false
|
93
|
+
end
|
94
|
+
|
95
|
+
def create_data_file(context)
|
96
|
+
puts "Creating product file: #{@outfile}" if context.verbose
|
97
|
+
File.open(context.outputPath(@outfile), "w") do |f|
|
98
|
+
write_to_file(f,@openTag)
|
99
|
+
|
100
|
+
# Write the product PPM's Xpath (which was stored in the context)
|
101
|
+
write_to_file(f,context[:productXpath] ) if ! context[:productXpath].nil?
|
102
|
+
|
103
|
+
write_to_file(f,@data)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def accept_product_ppms(context, ln)
|
108
|
+
if ln.include?(@searchStr2)
|
109
|
+
context.state = :productPpms
|
110
|
+
|
111
|
+
# XML Tidy doesn't like underscores at the beginning attribute names, take care of it here.
|
112
|
+
ln.gsub!(/_DATA_SET/, "DATA_SET")
|
113
|
+
ln.gsub!(/_Name/, "Name")
|
114
|
+
ln.gsub!(/_Value/, "Value")
|
115
|
+
|
116
|
+
@data << ln
|
117
|
+
return true
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def accept_product_rules(context, ln)
|
122
|
+
if( ln.include?(@ruleStartStr) || ln.include?(@gdlStartStr) )
|
123
|
+
context.state = :productRules
|
124
|
+
|
125
|
+
@data << ln
|
126
|
+
return true
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def process_product_rules(context, ln)
|
131
|
+
if !ln.include?(@stopStr)
|
132
|
+
@data << ln
|
133
|
+
@lineCount += 1
|
134
|
+
|
135
|
+
write_data_chunk context
|
136
|
+
|
137
|
+
return true
|
138
|
+
else
|
139
|
+
|
140
|
+
@data << ln
|
141
|
+
@lineCount += 1
|
142
|
+
|
143
|
+
close_out_data_file context
|
144
|
+
context.state = :app
|
145
|
+
|
146
|
+
return true
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def write_data_chunk(context)
|
151
|
+
if(@lineCount > @chunkSize)
|
152
|
+
puts "Writing rule data chunk." if context.verbose
|
153
|
+
File.open(context.outputPath(@outfile), "a") do |f|
|
154
|
+
write_to_file(f,@data)
|
155
|
+
end
|
156
|
+
@lineCount = 0
|
157
|
+
@data.clear
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def close_out_data_file(context)
|
162
|
+
puts "Closing product file #{@outfile}." if context.verbose
|
163
|
+
File.open(context.outputPath(@outfile), "a") do |f|
|
164
|
+
write_to_file(f,@data)
|
165
|
+
write_to_file(f,@closeTag) # apply_template(@closeTag, "@TAG@", context.createValidName(@product))
|
166
|
+
end
|
167
|
+
@lineCount = 0
|
168
|
+
@data.clear
|
169
|
+
end
|
170
|
+
|
171
|
+
end # class Product
|
172
|
+
|
173
|
+
|
174
|
+
end # module Plugin
|
175
|
+
|
176
|
+
end # module ParseDecision
|
@@ -0,0 +1,52 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# File:: plugin.rb
|
3
|
+
# Purpose:: Plugin objects for ParseDecision utility
|
4
|
+
#
|
5
|
+
# Author:: Jeff McAffee 04/17/2010
|
6
|
+
# Copyright:: Copyright (c) 2010, kTech Systems LLC. All rights reserved.
|
7
|
+
# Website:: http://ktechsystems.com
|
8
|
+
##############################################################################
|
9
|
+
|
10
|
+
##############################################################################
|
11
|
+
module ParseDecision
|
12
|
+
|
13
|
+
##############################################################################
|
14
|
+
module Plugin
|
15
|
+
|
16
|
+
## #######################################################################
|
17
|
+
# Product XPath plugin
|
18
|
+
class ProductXpath < Plugin
|
19
|
+
def initialize()
|
20
|
+
$LOG.debug "ProductXpath::initialize"
|
21
|
+
@searchStr1 = "*PRODUCT XPATH xml*"
|
22
|
+
@searchStr2 = "<PPXPATH>"
|
23
|
+
end
|
24
|
+
|
25
|
+
def execute(context, ln)
|
26
|
+
#$LOG.debug "ProductXpath::execute"
|
27
|
+
if((context.state == :app) && ln.include?(@searchStr1))
|
28
|
+
context.state = :productXpath
|
29
|
+
return true
|
30
|
+
end
|
31
|
+
|
32
|
+
if((context.state == :productXpath) && ln.include?(@searchStr2))
|
33
|
+
context.state = :app
|
34
|
+
# We just store the product xpath in the context so it can
|
35
|
+
# be incorporated into the product rules file later.
|
36
|
+
context[:productXpath] = ln
|
37
|
+
return true
|
38
|
+
end
|
39
|
+
|
40
|
+
if(context.state == :productXpath)
|
41
|
+
# Probably a blank line. Claim it so we don't waste anyone else's time.
|
42
|
+
return true
|
43
|
+
end
|
44
|
+
|
45
|
+
return false
|
46
|
+
end
|
47
|
+
end # class ProductXpath
|
48
|
+
|
49
|
+
|
50
|
+
end # module Plugin
|
51
|
+
|
52
|
+
end # module ParseDecision
|
@@ -0,0 +1,179 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# File:: plugin.rb
|
3
|
+
# Purpose:: Plugin objects for ParseDecision utility
|
4
|
+
#
|
5
|
+
# Author:: Jeff McAffee 04/17/2010
|
6
|
+
# Copyright:: Copyright (c) 2010, kTech Systems LLC. All rights reserved.
|
7
|
+
# Website:: http://ktechsystems.com
|
8
|
+
##############################################################################
|
9
|
+
|
10
|
+
##############################################################################
|
11
|
+
module ParseDecision
|
12
|
+
|
13
|
+
##############################################################################
|
14
|
+
module Plugin
|
15
|
+
|
16
|
+
## #######################################################################
|
17
|
+
# Product info plugin - specific to webdecisions
|
18
|
+
class WebProduct < Plugin
|
19
|
+
attr_reader :data
|
20
|
+
|
21
|
+
def initialize()
|
22
|
+
$LOG.debug "WebProduct::initialize"
|
23
|
+
@fnameTemplate = "@INDEX@-@PROD@-PRODUCT.xml"
|
24
|
+
|
25
|
+
@ruleStartStr = "<Rules>"
|
26
|
+
@gdlStartStr = "<Decision GuidelineId"
|
27
|
+
@stopStr = "</Decision>"
|
28
|
+
|
29
|
+
@openProgramNameDpm = '>'
|
30
|
+
@closeProgramNameDpm = '</DPM>'
|
31
|
+
|
32
|
+
|
33
|
+
@data = []
|
34
|
+
@outfile = ""
|
35
|
+
@openTag = "<@TAG@_DATA>\n"
|
36
|
+
@closeTag = "</@TAG@_DATA>\n"
|
37
|
+
@openTag = "<PRODUCT_DATA>\n"
|
38
|
+
@closeTag = "</PRODUCT_DATA>\n"
|
39
|
+
@lineCount = 0
|
40
|
+
@chunkSize = 1000
|
41
|
+
@product = ""
|
42
|
+
@productIndex = 1
|
43
|
+
@appIndex = "00"
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def productIndexStr()
|
48
|
+
return "%02d" % @productIndex
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def execute(context, ln)
|
53
|
+
#$LOG.debug "WebProduct::execute"
|
54
|
+
if((context.state == :app) && ln.include?(@ruleStartStr))
|
55
|
+
context.state = :gdlRules
|
56
|
+
@data.clear
|
57
|
+
@outfile = ""
|
58
|
+
context["programNameFound"] = false
|
59
|
+
context["productName"] = ""
|
60
|
+
|
61
|
+
if(!@appIndex.eql?(context.indexStr))
|
62
|
+
@productIndex = 1
|
63
|
+
@appIndex = context.indexStr
|
64
|
+
end
|
65
|
+
|
66
|
+
product = "Product" + productIndexStr()
|
67
|
+
@productIndex += 1
|
68
|
+
@product = context.createValidName(product)
|
69
|
+
@outfile = apply_templates(@fnameTemplate, {"@INDEX@"=>context.indexStr, "@PROD@"=>@product})
|
70
|
+
puts "" if context.verbose
|
71
|
+
puts "- + - + - + -" if context.verbose
|
72
|
+
puts "" if context.verbose
|
73
|
+
puts "Creating product file: #{@outfile}" if context.verbose
|
74
|
+
@data << ln
|
75
|
+
File.open(context.outputPath(@outfile), "w") do |f|
|
76
|
+
write_to_file(f,@openTag) # apply_template(@openTag, "@TAG@", context.createValidName(@product))
|
77
|
+
write_to_file(f,context[:productXpath]) if ! context[:productXpath].nil?
|
78
|
+
write_to_file(f,@data)
|
79
|
+
end
|
80
|
+
@data.clear
|
81
|
+
return true
|
82
|
+
end
|
83
|
+
|
84
|
+
if((context.state == :gdlRules))
|
85
|
+
context.state = :productRules
|
86
|
+
|
87
|
+
@data << ln
|
88
|
+
return true
|
89
|
+
end
|
90
|
+
|
91
|
+
if((context.state == :productRules) && !ln.include?(@stopStr))
|
92
|
+
if(ln.include?("----")) # Skip comment lines (they are not valid XML).
|
93
|
+
commentLine = ln.slice(0,4)
|
94
|
+
return true if(commentLine.include?("----"))
|
95
|
+
end
|
96
|
+
|
97
|
+
@data << ln
|
98
|
+
@lineCount += 1
|
99
|
+
|
100
|
+
if(!context["programNameFound"])
|
101
|
+
if(ln.include?('Name="Program Name"'))
|
102
|
+
productName = getSubString(ln, @openProgramNameDpm, @closeProgramNameDpm)
|
103
|
+
context["programNameFound"] = true
|
104
|
+
context["productName"] = productName
|
105
|
+
puts "........Program Name DPM found: #{productName}" if context.verbose
|
106
|
+
|
107
|
+
end # if ln.include?
|
108
|
+
end # if !context["programNameFound"]
|
109
|
+
|
110
|
+
if(@lineCount > @chunkSize)
|
111
|
+
puts "Writing rule data chunk." if context.verbose
|
112
|
+
File.open(context.outputPath(@outfile), "a") do |f|
|
113
|
+
write_to_file(f,@data)
|
114
|
+
end
|
115
|
+
@lineCount = 0
|
116
|
+
@data.clear
|
117
|
+
end
|
118
|
+
return true
|
119
|
+
end
|
120
|
+
|
121
|
+
if((context.state == :productRules) && ln.include?(@stopStr))
|
122
|
+
@data << ln
|
123
|
+
@lineCount += 1
|
124
|
+
|
125
|
+
puts "Closing product file." if context.verbose
|
126
|
+
File.open(context.outputPath(@outfile), "a") do |f|
|
127
|
+
write_to_file(f,@data)
|
128
|
+
write_to_file(f,@closeTag) # apply_template(@closeTag, "@TAG@", context.createValidName(@product))
|
129
|
+
end
|
130
|
+
@lineCount = 0
|
131
|
+
@data.clear
|
132
|
+
context.state = :app
|
133
|
+
#@productIndex = 1
|
134
|
+
|
135
|
+
if(context["programNameFound"])
|
136
|
+
pname = context.createValidName(context["productName"])
|
137
|
+
newFileName = apply_templates(@fnameTemplate, {"@INDEX@"=>context.indexStr, "@PROD@"=>pname})
|
138
|
+
|
139
|
+
renameFile(context, @outfile, newFileName)
|
140
|
+
end # if context["programNameFound"]
|
141
|
+
|
142
|
+
context["programNameFound"] = false
|
143
|
+
|
144
|
+
return true
|
145
|
+
end
|
146
|
+
|
147
|
+
return false
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
def getSubString(haystack, startDelim, stopDelim)
|
152
|
+
#$LOG.debug "WebProduct::getSubString( #{haystack}, #{startDelim}, #{stopDelim} )"
|
153
|
+
#puts "WebProduct::getSubString()" # #{haystack}, #{startDelim}, #{stopDelim} )"
|
154
|
+
#puts " haystack: #{haystack}"
|
155
|
+
#puts " startDelim: #{startDelim}"
|
156
|
+
#puts " stopDelim: #{stopDelim}"
|
157
|
+
|
158
|
+
start = haystack.index(startDelim)
|
159
|
+
#puts " start: " + (start.nil? ? "nil" : "#{start}")
|
160
|
+
return if start.nil?
|
161
|
+
|
162
|
+
start += startDelim.size
|
163
|
+
stop = haystack.rindex(stopDelim)
|
164
|
+
|
165
|
+
res = haystack[start,(stop - start)]
|
166
|
+
end # getSubString
|
167
|
+
|
168
|
+
|
169
|
+
def renameFile(context, srcFileName, destFileName)
|
170
|
+
puts "Renaming #{srcFileName} => #{destFileName}" if context.verbose
|
171
|
+
FileUtils.mv(context.outputPath(srcFileName), context.outputPath(destFileName))
|
172
|
+
end # renameFile
|
173
|
+
|
174
|
+
|
175
|
+
end # class WebProduct
|
176
|
+
|
177
|
+
end # module Plugin
|
178
|
+
|
179
|
+
end # module ParseDecision
|
@@ -0,0 +1,50 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# File:: plugin.rb
|
3
|
+
# Purpose:: Plugin objects for ParseDecision utility
|
4
|
+
#
|
5
|
+
# Author:: Jeff McAffee 04/17/2010
|
6
|
+
# Copyright:: Copyright (c) 2010, kTech Systems LLC. All rights reserved.
|
7
|
+
# Website:: http://ktechsystems.com
|
8
|
+
##############################################################################
|
9
|
+
|
10
|
+
#############################################################
|
11
|
+
# Stage Change Flow
|
12
|
+
#
|
13
|
+
# default mode:
|
14
|
+
# :app
|
15
|
+
# :appPpmXpath
|
16
|
+
# :preDecisionGdl
|
17
|
+
# :productXpath
|
18
|
+
# :productXml
|
19
|
+
# :productPpms
|
20
|
+
# :productRules
|
21
|
+
#
|
22
|
+
# webdecision mode:
|
23
|
+
# :app
|
24
|
+
# :gdlRules
|
25
|
+
# :productRules
|
26
|
+
# :decisionResponse
|
27
|
+
# :preDecisionGdl
|
28
|
+
#
|
29
|
+
#
|
30
|
+
#
|
31
|
+
#
|
32
|
+
#############################################################
|
33
|
+
|
34
|
+
|
35
|
+
##############################################################################
|
36
|
+
module ParseDecision
|
37
|
+
|
38
|
+
##############################################################################
|
39
|
+
module Plugin
|
40
|
+
|
41
|
+
end # module Plugin
|
42
|
+
end # module ParseDecision
|
43
|
+
|
44
|
+
require_relative 'plugin/plugin'
|
45
|
+
require_relative 'plugin/application'
|
46
|
+
require_relative 'plugin/ppm_xpath'
|
47
|
+
require_relative 'plugin/pre_decision_guideline'
|
48
|
+
require_relative 'plugin/product'
|
49
|
+
require_relative 'plugin/product_xpath'
|
50
|
+
require_relative 'plugin/web_product'
|
@@ -0,0 +1,59 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# File:: parse_decision.rb
|
3
|
+
# Purpose:: Include file for ParseDecision library
|
4
|
+
#
|
5
|
+
# Author:: Jeff McAffee 03/12/2010
|
6
|
+
# Copyright:: Copyright (c) 2010, kTech Systems LLC. All rights reserved.
|
7
|
+
# Website:: http://ktechsystems.com
|
8
|
+
##############################################################################
|
9
|
+
|
10
|
+
require 'find'
|
11
|
+
require 'logger'
|
12
|
+
require 'bundler/setup'
|
13
|
+
|
14
|
+
|
15
|
+
if(!$LOG)
|
16
|
+
$LOG = Logger.new(STDERR)
|
17
|
+
$LOG.level = Logger::ERROR
|
18
|
+
end
|
19
|
+
|
20
|
+
if ENV["DEBUG"] == '1'
|
21
|
+
puts "LOGGING: ON due to DEBUG=1"
|
22
|
+
$LOG.level = Logger::DEBUG
|
23
|
+
end
|
24
|
+
|
25
|
+
$LOGGING = false
|
26
|
+
# Uncomment line below to force logging:
|
27
|
+
#$LOGGING = true # TODO: Change this flag to false when releasing production build.
|
28
|
+
|
29
|
+
require "#{File.join( File.dirname(__FILE__), 'parse_decision','version')}"
|
30
|
+
require "#{File.join( File.dirname(__FILE__), 'parse_decision','config')}"
|
31
|
+
|
32
|
+
logcfg = ParseDecision::Config.new.load
|
33
|
+
if(logcfg.key?(:logging) && (true == logcfg[:logging]) )
|
34
|
+
$LOGGING = true
|
35
|
+
end
|
36
|
+
|
37
|
+
if($LOGGING)
|
38
|
+
# Create a new log file each time:
|
39
|
+
file = File.open('parse_decision.log', File::WRONLY | File::APPEND | File::CREAT | File::TRUNC)
|
40
|
+
$LOG = Logger.new(file)
|
41
|
+
$LOG.level = Logger::DEBUG
|
42
|
+
#$LOG.level = Logger::INFO
|
43
|
+
else
|
44
|
+
if(File.exists?('parse_decision.log'))
|
45
|
+
FileUtils.rm('parse_decision.log')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
$LOG.info "**********************************************************************"
|
49
|
+
$LOG.info "Logging started for ParseDecision library."
|
50
|
+
$LOG.info "**********************************************************************"
|
51
|
+
|
52
|
+
|
53
|
+
class_files = File.join( File.dirname(__FILE__), 'parse_decision', '*.rb')
|
54
|
+
$: << File.join( File.dirname(__FILE__), 'parse_decision') # Add directory to the include file array.
|
55
|
+
Dir.glob(class_files) do | class_file |
|
56
|
+
require class_file[/\w+\.rb$/]
|
57
|
+
end
|
58
|
+
|
59
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'parse_decision/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.platform = Gem::Platform::RUBY
|
8
|
+
spec.name = "parse_decision"
|
9
|
+
spec.version = ParseDecision::VERSION
|
10
|
+
spec.authors = ["Jeff McAffee"]
|
11
|
+
spec.email = ["jeff@ktechsystems.com"]
|
12
|
+
spec.description = %q{AMS Decision Log Parser}
|
13
|
+
spec.summary = %q{AMS Decision Log Parser}
|
14
|
+
spec.homepage = "https://github.com/jmcaffee/parse_decision"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec-given"
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
spec.add_runtime_dependency "ktcommon"
|
27
|
+
end
|
data/rakefile.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
######################################################################################
|
2
|
+
# File:: rakefile
|
3
|
+
# Purpose:: Build tasks for ParseDecision application
|
4
|
+
#
|
5
|
+
# Author:: Jeff McAffee 03/12/2010
|
6
|
+
# Copyright:: Copyright (c) 2010, kTech Systems LLC. All rights reserved.
|
7
|
+
# Website:: http://ktechsystems.com
|
8
|
+
######################################################################################
|
9
|
+
|
10
|
+
require 'bundler/gem_tasks'
|
11
|
+
require 'psych'
|
12
|
+
gem 'rdoc', '>= 3.9.4'
|
13
|
+
|
14
|
+
require 'rake'
|
15
|
+
require 'rake/clean'
|
16
|
+
require 'rdoc/task'
|
17
|
+
|
18
|
+
|
19
|
+
# Set the project name
|
20
|
+
PROJNAME = "ParseDecision"
|
21
|
+
|
22
|
+
|
23
|
+
#############################################################################
|
24
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
25
|
+
files = ['README.rdoc', 'docs/**/*.rdoc', 'lib/**/*.rb', 'bin/**/*']
|
26
|
+
rdoc.rdoc_files.add( files )
|
27
|
+
# Page to start on
|
28
|
+
rdoc.main = "README.md"
|
29
|
+
#puts "PWD: #{FileUtils.pwd}"
|
30
|
+
rdoc.title = "#{PROJNAME} Documentation"
|
31
|
+
rdoc.rdoc_dir = 'doc' # rdoc output folder
|
32
|
+
rdoc.options << '--line-numbers' << '--all'
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
#############################################################################
|
38
|
+
desc "Run all tests"
|
39
|
+
task :test => [:init] do
|
40
|
+
unless File.directory?('test')
|
41
|
+
$stderr.puts 'no test in this package'
|
42
|
+
return
|
43
|
+
end
|
44
|
+
$stderr.puts 'Running tests...'
|
45
|
+
TESTDIR = "test"
|
46
|
+
begin
|
47
|
+
require 'test/unit'
|
48
|
+
rescue LoadError
|
49
|
+
$stderr.puts 'test/unit cannot loaded. You need Ruby 1.8 or later to invoke this task.'
|
50
|
+
end
|
51
|
+
|
52
|
+
$LOAD_PATH.unshift("./")
|
53
|
+
$LOAD_PATH.unshift(TESTDIR)
|
54
|
+
Dir[File.join(TESTDIR, "*.rb")].each {|file| require File.basename(file) }
|
55
|
+
require 'minitest/autorun'
|
56
|
+
end
|
57
|
+
|
58
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ParseDecision::PDContext do
|
4
|
+
|
5
|
+
let(:context) { ParseDecision::PDContext.new }
|
6
|
+
|
7
|
+
it "throws an exception if invalid target state is requested" do
|
8
|
+
expect { context.state = :notAValidState }.to raise_error("Invalid target state: notAValidState")
|
9
|
+
end
|
10
|
+
|
11
|
+
Given(:target_dir) { 'spec/data' }
|
12
|
+
Given(:target_file) { 'testfile.txt' }
|
13
|
+
|
14
|
+
context "#src_file sets the source dir and file" do
|
15
|
+
When { context.src_file = File.join(target_dir, target_file) }
|
16
|
+
|
17
|
+
Then { context.srcdir.should eq target_dir }
|
18
|
+
Then { context.file.should eq target_file }
|
19
|
+
end
|
20
|
+
|
21
|
+
end # describe ParseDecision::PDContext
|