Skip to content

Instantly share code, notes, and snippets.

View pmcneil's full-sized avatar

Peter McNeil pmcneil

View GitHub Profile
question("S1"){
"Select something" select: ['one','two','three','four','five'],
map: 'selectme',
hint: 'select one of the options',
default: 'three',
preamble: 'Yep you can explain this with a preamble'
}
@pmcneil
pmcneil / AllElementsForm.groovy
Last active December 17, 2015 06:08
This shows all the form elements in a single question for example and testing
form {
question("test") {
"All elements" group: "theLot",
hint: 'This is a group', {
"Text input 20?" text: 20,
map: 'text20',
hint: 'this is a 20 char text',
preamble: 'This is 20 char text with a pattern match so only letters can be entered',
pattern: [/[A-Za-z]+/, 'You can only have letters'],
sugest: 'colour',
@pmcneil
pmcneil / TestRules.groovy
Last active December 16, 2015 18:50
Script to test One Ring rules.
import com.nerderg.rules.RulesEngine
import com.nerderg.rules.RulesetDelegate
import groovy.io.FileType
/**
* User: pmcneil
* Date: 18/10/11
*
*/
File dir = new File(".")
def nameMatch = ~/.*\.ruleset/
rule('M8 Fap Health Care Card') {
def faps = fact.fap
faps.each { fap ->
def M8Q = fact.M8.fap[fapName(fap)]
if (M8Q?.yes && M8Q.healthCard == 'none') {
fact.require.add([Q: 'M8', message: "a copy of ${fap}'s health care or pensioner concession card."])
}
}
}
@pmcneil
pmcneil / questionExample.groovy
Created March 17, 2013 03:52
Example Good Form question definition
question("G2") {
"What is your name?" group: "names", hint: "Name of the person requiring assistance", {
"Title" text: 10, hint: "e.g. Mr, Mrs, Ms, Miss, Dr", suggest: "title", map: 'title'
"Given Names" text: 50, required: true, map: 'givenNames'
"Last or Family Name" text: 50, required: true, map: 'lastName'
"Have you been or are you known by any other names?" hint: "e.g. maiden name, previous married name, alias, name at birth", map: 'knownByOtherNames',{
"List your other names" listOf: "aliases", {
"Other name" text: 50, map: 'otherName'
"Type of name" text: 40, hint: "e.g maiden name", suggest: "nameType", map: 'otherNameType'
}
@pmcneil
pmcneil / TestRules.groovy
Created February 14, 2013 04:54
One Ring Rules test code. This lets you run tests on Rules while designing them, in you IDE.
import com.nerderg.rules.RulesEngine
import com.nerderg.rules.RulesetDelegate
import groovy.io.FileType
/**
* User: pmcneil
* Date: 18/10/11
*
*/
File dir = new File(".")
def nameMatch = ~/.*\.ruleset/
@pmcneil
pmcneil / TestRules.groovy
Created May 3, 2012 23:03
Read in rulesets and test on rules engine
import com.nerderg.rules.RulesEngine
import com.nerderg.rules.RulesetDelegate
import groovy.io.FileType
/**
* User: pmcneil
* Date: 18/10/11
*
*/
File dir = new File(".")
def nameMatch = ~/.*\.ruleset/
import com.nerderg.rules.RulesEngine
import com.nerderg.rules.RulesetDelegate
import groovy.io.FileType
/**
* User: pmcneil
* Date: 18/10/11
*
*/
File dir = new File(".")
def nameMatch = ~/.*\.ruleset/
@pmcneil
pmcneil / addAllOperator.groovy
Created October 25, 2011 11:00
addAll operator hack for Groovy?
void testSomething() {
Collection.metaClass.and = { Collection b ->
addAll(b)
}
List a = ['one','two', 'three']
List b = ['four', 'five']
a & b
println a
assert a == ['one','two', 'three','four', 'five']
}
@pmcneil
pmcneil / testController.groovy
Created January 25, 2011 05:11
This demonstrates a pattern suggested here http://bit.ly/h24hXy
package com.nerderg.test
class TestController {
def index = {
}
def changeColour = {
withPerson {
log.debug dump()