Class: Ruler
- Inherits:
-
Object
- Object
- Ruler
- Defined in:
- lib/Ruler.rb
Constant Summary collapse
- INPUT =
"i"- OUTPUT =
"o"- TYPE =
"T"- VALUE =
"V"
Instance Method Summary collapse
-
#initialize ⇒ Ruler
constructor
A new instance of Ruler.
- #load(controls) ⇒ Object
- #load_rule_pool(rule_pool, type, value) ⇒ Object
- #train ⇒ Object
- #validate_inputs(inputs) ⇒ Object
- #validate_output(output) ⇒ Object
Constructor Details
#initialize ⇒ Ruler
Returns a new instance of Ruler.
16 17 18 19 20 21 22 23 24 |
# File 'lib/Ruler.rb', line 16 def initialize() # Reflections. @controls = nil # Arguments. @inputs = [] @output = nil end |
Instance Method Details
#load(controls) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/Ruler.rb', line 26 def load(controls) @controls = controls @controls.each_with_index do |control, index| # Create rules for each input. control[INPUT].each_with_index do |input, index| unless input.nil? @inputs[index] = load_rule_pool(@inputs[index], input[TYPE], input[VALUE]) end end # Create rules for the output. output = control[OUTPUT] unless control[OUTPUT].nil? @output = load_rule_pool(@output, output[TYPE], output[VALUE]) end end end |
#load_rule_pool(rule_pool, type, value) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/Ruler.rb', line 48 def load_rule_pool(rule_pool, type, value) if rule_pool.nil? rule_pool = RulePool.new() end # Track data type. rule_pool.types << type # Get rule for this data type. rule = nil case type when "Integer" unless rule_pool.rules.key? IntegerRule rule = IntegerRule.new() rule_pool.rules << rule else rule = rule_pool.rules[IntegerRule] end when "String" unless rule_pool.rules.key? StringRule rule = StringRule.new() rule_pool.rules << rule else rule = rule_pool.rules[IntegerRule] end end # Add value to rule. unless rule.nil? rule.load(value) end return rule_pool end |
#train ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/Ruler.rb', line 86 def train() @inputs.each do |rule_pool| unless rule_pool.nil? rule_pool.train() end end unless @output.nil? @output.train() end end |
#validate_inputs(inputs) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/Ruler.rb', line 100 def validate_inputs(inputs) result = true inputs.each_with_index do |value, index| rule_pool = @inputs[index] unless rule_pool.validate(input) result = false end end return result end |
#validate_output(output) ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/Ruler.rb', line 113 def validate_output(output) result = true rule_pool = @output unless rule_pool.validate(output) result = false end return result end |