reflekt 0.9.7 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  ################################################################################
2
- # SHADOW STACK
2
+ # Track the executions in a shadow call stack.
3
3
  #
4
- # Track the executions in a call stack.
4
+ # @pattern Stack
5
5
  ################################################################################
6
6
 
7
7
  class ShadowStack
@@ -20,24 +20,23 @@ class ShadowStack
20
20
  end
21
21
 
22
22
  ##
23
- # Push Execution.
23
+ # Place Execution at the top of stack.
24
24
  #
25
- # @param object - The object being executed.
26
- # @param args - The arguments being executed.
27
- #
28
- # @return Execution - The new execution.
25
+ # @param execution [Execution] The execution to place.
26
+ # @return [Execution] The placed execution.
29
27
  ##
30
28
  def push(execution)
31
29
 
32
- # Reference previous execution.
30
+ # Place first execution at bottom of stack.
33
31
  if @bottom.nil?
34
32
  @bottom = execution
33
+ # Connect subsequent executions to each other.
35
34
  else
36
- execution.child = @top
37
35
  @top.parent = execution
36
+ execution.child = @top
38
37
  end
39
38
 
40
- # Place new execution at the top of the stack.
39
+ # Place execution at top of stack.
41
40
  @top = execution
42
41
 
43
42
  end
@@ -0,0 +1,34 @@
1
+ require 'Meta'
2
+
3
+ class ArrayMeta < Meta
4
+
5
+ def initialize()
6
+
7
+ @type = :array
8
+ @min = nil
9
+ @max = nil
10
+ @length = nil
11
+
12
+ end
13
+
14
+ ##
15
+ # @param value [Array]
16
+ ##
17
+ def load(value)
18
+
19
+ @min = value.min()
20
+ @max = value.max()
21
+ @length = value.length()
22
+
23
+ end
24
+
25
+ def serialize()
26
+ {
27
+ :type => @type,
28
+ :max => @max,
29
+ :min => @min,
30
+ :length => @length
31
+ }
32
+ end
33
+
34
+ end
@@ -0,0 +1,26 @@
1
+ require 'Meta'
2
+
3
+ class BooleanMeta < Meta
4
+
5
+ def initialize()
6
+
7
+ @type = :bool
8
+ @value = nil
9
+
10
+ end
11
+
12
+ ##
13
+ # @param value [Boolean]
14
+ ##
15
+ def load(value)
16
+ @value = value.to_s
17
+ end
18
+
19
+ def serialize()
20
+ {
21
+ :type => @type,
22
+ :value => @value
23
+ }
24
+ end
25
+
26
+ end
@@ -0,0 +1,26 @@
1
+ require 'Meta'
2
+
3
+ class FloatMeta < Meta
4
+
5
+ def initialize()
6
+
7
+ @type = :float
8
+ @value = nil
9
+
10
+ end
11
+
12
+ ##
13
+ # @param value [Float]
14
+ ##
15
+ def load(value)
16
+ @value = value
17
+ end
18
+
19
+ def serialize()
20
+ {
21
+ :type => @type,
22
+ :value => @value
23
+ }
24
+ end
25
+
26
+ end
@@ -0,0 +1,26 @@
1
+ require 'Meta'
2
+
3
+ class IntegerMeta < Meta
4
+
5
+ def initialize()
6
+
7
+ @type = :int
8
+ @value = nil
9
+
10
+ end
11
+
12
+ ##
13
+ # @param value [Integer]
14
+ ##
15
+ def load(value)
16
+ @value = value
17
+ end
18
+
19
+ def serialize()
20
+ {
21
+ :type => @type,
22
+ :value => @value
23
+ }
24
+ end
25
+
26
+ end
@@ -0,0 +1,34 @@
1
+ ################################################################################
2
+ # A reprsentation of a null value.
3
+ #
4
+ # @note
5
+ # A "null" value on serialized "inputs" and "output" also becomes a NullMeta.
6
+ #
7
+ # @hierachy
8
+ # 1. Execution
9
+ # 2. Reflection
10
+ # 3. Meta <- YOU ARE HERE
11
+ ################################################################################
12
+
13
+ require 'Meta'
14
+
15
+ class NullMeta < Meta
16
+
17
+ def initialize()
18
+ @type = :null
19
+ end
20
+
21
+ ##
22
+ # @param value [NilClass]
23
+ ##
24
+ def load(value)
25
+ # No need to load a value for null meta.
26
+ end
27
+
28
+ def serialize()
29
+ {
30
+ :type => @type,
31
+ }
32
+ end
33
+
34
+ end
@@ -0,0 +1,26 @@
1
+ require 'Meta'
2
+
3
+ class StringMeta < Meta
4
+
5
+ def initialize()
6
+
7
+ @type = :string
8
+ @length = nil
9
+
10
+ end
11
+
12
+ ##
13
+ # @param value [String]
14
+ ##
15
+ def load(value)
16
+ @length = value.length
17
+ end
18
+
19
+ def serialize()
20
+ {
21
+ :type => @type,
22
+ :length => @length
23
+ }
24
+ end
25
+
26
+ end
@@ -0,0 +1,88 @@
1
+ require 'Rule'
2
+
3
+ class ArrayRule < Rule
4
+
5
+ def initialize()
6
+
7
+ @type = :array
8
+ @min = nil
9
+ @max = nil
10
+ @min_length = nil
11
+ @max_length = nil
12
+
13
+ end
14
+
15
+ ##
16
+ # @param meta [ArrayMeta]
17
+ ##
18
+ def train(meta)
19
+
20
+ # Min value.
21
+ if @min.nil?
22
+ @min = meta[:min]
23
+ else
24
+ @min = meta[:min] if meta[:min] < @min
25
+ end
26
+
27
+ # Max value.
28
+ if @max.nil?
29
+ @max = meta[:max]
30
+ else
31
+ @max = meta[:max] if meta[:max] > @max
32
+ end
33
+
34
+ # Min length.
35
+ if @min_length.nil?
36
+ @min_length = meta[:length]
37
+ else
38
+ @min_length = meta[:length] if meta[:length] < @min_length
39
+ end
40
+
41
+ # Max length.
42
+ if @max_length.nil?
43
+ @max_length = meta[:length]
44
+ else
45
+ @max_length = meta[:length] if meta[:length] > @max_length
46
+ end
47
+
48
+ end
49
+
50
+ ##
51
+ # @param value [Array]
52
+ ##
53
+ def test(value)
54
+
55
+ # Min/max value.
56
+ return false if value.min() < @min
57
+ return false if value.max() > @max
58
+
59
+ # Min/max length.
60
+ return false if value.length < @min_length
61
+ return false if value.length > @max_length
62
+
63
+ true
64
+ end
65
+
66
+ def result()
67
+ {
68
+ :type => @type,
69
+ :min => @min,
70
+ :max => @max,
71
+ :min_length => @min_length,
72
+ :max_length => @max_length
73
+ }
74
+ end
75
+
76
+ def random()
77
+
78
+ array = Array.new(rand(@min_length..@max_length))
79
+
80
+ array.each_with_index do |item, index|
81
+ array[index] = rand(@min..@max)
82
+ end
83
+
84
+ return array
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1,47 @@
1
+ require 'set'
2
+ require 'Rule'
3
+
4
+ class BooleanRule < Rule
5
+
6
+ def initialize()
7
+
8
+ @type = :bool
9
+ @booleans = Set.new()
10
+
11
+ end
12
+
13
+ ##
14
+ # @param meta [BooleanMeta]
15
+ ##
16
+ def train(meta)
17
+
18
+ value = meta[:value]
19
+
20
+ unless value.nil?
21
+ @booleans << value
22
+ end
23
+
24
+ end
25
+
26
+ ##
27
+ # @param value [Boolean]
28
+ ##
29
+ def test(value)
30
+
31
+ # Booleans are stored as strings.
32
+ @booleans.include? value.to_s
33
+
34
+ end
35
+
36
+ def result()
37
+ {
38
+ :type => @type,
39
+ :booleans => @booleans
40
+ }
41
+ end
42
+
43
+ def random()
44
+ @booleans.to_a.sample
45
+ end
46
+
47
+ end
@@ -2,27 +2,56 @@ require 'Rule'
2
2
 
3
3
  class FloatRule < Rule
4
4
 
5
- attr_accessor :min
6
- attr_accessor :max
7
-
8
5
  def initialize()
9
- super
10
6
 
7
+ @type = :float
11
8
  @min = nil
12
9
  @max = nil
13
- end
14
10
 
15
- def load(value)
16
- @values << value
17
11
  end
18
12
 
19
- def train()
20
- # TODO.
13
+ ##
14
+ # @param meta [FloatMeta]
15
+ ##
16
+ def train(meta)
17
+
18
+ value = meta[:value]
19
+
20
+ if @min.nil?
21
+ @min = value
22
+ else
23
+ @min = value if value < @min
24
+ end
25
+
26
+ if @max.nil?
27
+ @max = value
28
+ else
29
+ @max = value if value > @max
30
+ end
31
+
21
32
  end
22
33
 
23
- def validate(value)
24
- # TODO.
34
+ ##
35
+ # @param value [Float]
36
+ ##
37
+ def test(value)
38
+
39
+ return false if value < @min
40
+ return false if value > @max
41
+
25
42
  true
26
43
  end
27
44
 
45
+ def result()
46
+ {
47
+ :type => @type,
48
+ :min => @min,
49
+ :max => @max
50
+ }
51
+ end
52
+
53
+ def random()
54
+ rand(@min..@max)
55
+ end
56
+
28
57
  end
@@ -3,24 +3,38 @@ require 'Rule'
3
3
  class IntegerRule < Rule
4
4
 
5
5
  def initialize()
6
+
7
+ @type = :int
6
8
  @min = nil
7
9
  @max = nil
8
10
 
9
- super
10
11
  end
11
12
 
12
- def load(value)
13
- @values << value.to_i
14
- end
13
+ ##
14
+ # @param meta [IntegerMeta]
15
+ ##
16
+ def train(meta)
17
+
18
+ value = meta[:value]
19
+
20
+ if @min.nil?
21
+ @min = value
22
+ else
23
+ @min = value if value < @min
24
+ end
25
+
26
+ if @max.nil?
27
+ @max = value
28
+ else
29
+ @max = value if value > @max
30
+ end
15
31
 
16
- def train()
17
- numbers = @values.select {|num| num.class == Integer }
18
- numbers.sort!
19
- @min = numbers.first
20
- @max = numbers.last
21
32
  end
22
33
 
23
- def validate(value)
34
+ ##
35
+ # @param value [Integer]
36
+ ##
37
+ def test(value)
24
38
 
25
39
  return false if value < @min
26
40
  return false if value > @max
@@ -28,4 +42,16 @@ class IntegerRule < Rule
28
42
  true
29
43
  end
30
44
 
45
+ def result()
46
+ {
47
+ :type => @type,
48
+ :min => @min,
49
+ :max => @max
50
+ }
51
+ end
52
+
53
+ def random()
54
+ rand(@min..@max)
55
+ end
56
+
31
57
  end