Skip to content

Commit

Permalink
Access correct input/output structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
maedi committed Oct 3, 2020
1 parent 3dc9805 commit edcd0c9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 43 deletions.
71 changes: 30 additions & 41 deletions lib/Ruler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,22 @@ def initialize()

@controls = nil
@inputs = []
@outputs = []
@output = nil

end

def load(controls)

@controls = controls
@controls.each do |control_key, control|
@controls.each_with_index do |control, index|

# TODO: Figure out why timestamp, "p" and "nil" items leaking through.
unless control.class == Hash || control.class == Array
next
end

if control.class == Array
if control.empty?
next
end
unless control.first.nil?
control = control.first
end
end

unless control[INPUT].nil? || control[INPUT].empty?
p '-----'
p control
p '-----'

control[INPUT].each_with_index do |input, index|
# Multiple inputs.
control[INPUT].each_with_index do |input, index|
unless input.nil?

# Create rule.
if @inputs[index].nil?
Expand All @@ -54,29 +44,30 @@ def load(controls)
rule.add_value(input[VALUE])
end

index = index + 1
end
end

unless control[OUTPUT].nil? || control[OUTPUT].empty?
control[OUTPUT].each_with_index do |output, index|

# Create rule.
if @outputs[index].nil?
rule = Rule.new()
@outputs[index] = rule
else
rule = @outputs[index]
end
# Singular output.
output = control[OUTPUT]
unless control[OUTPUT].nil?

# Add rules to rule.
unless output[TYPE].nil? || output[TYPE].empty?
rule.add_type(output[TYPE])
end
unless output[VALUE].nil? || output[VALUE].empty?
rule.add_value(output[VALUE])
end
# Create rule.
if @output.nil?
rule = Rule.new()
@output = rule
else
rule = @output
end

## Add rules to rule.
unless output[TYPE].nil? || output[TYPE].empty?
rule.add_type(output[TYPE])
end
unless output[VALUE].nil? || output[VALUE].empty?
rule.add_value(output[VALUE])
end

end

end
Expand Down Expand Up @@ -112,12 +103,10 @@ def validate_input(klass, method, inputs)

def validate_output(klass, method, outputs)
result = true
outputs.each_with_index do |value, index|
rule = @outputs[index]
if rule.is_number? && value.class == Integer
result = false if value < rule.min
result = false if value > rule.max
end
rule = @output
if rule.is_number? && value.class == Integer
result = false if value < rule.min
result = false if value > rule.max
end
return result
end
Expand Down
3 changes: 1 addition & 2 deletions lib/reflekt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ def self.reflekt_setup_class()
if method_values.key? "controls"

ruler = Ruler.new()
# TODO: Remove array with one value.
ruler.load(method_values['controls'].first)
ruler.load(method_values['controls'])
ruler.train()

@@reflekt_rules[class_name][method_name] = ruler
Expand Down

0 comments on commit edcd0c9

Please sign in to comment.