reflekt 0.9.6 → 1.0.1

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.
@@ -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,37 +20,25 @@ 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
44
43
 
45
- def display
46
- display_execution_tree(@bottom)
47
- end
48
-
49
- def display_execution_tree(execution)
50
- p execution
51
- unless execution.parent == nil
52
- display_execution_tree(execution.parent)
53
- end
54
- end
55
-
56
44
  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 result()
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 result()
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 result()
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 result()
20
+ {
21
+ :type => @type,
22
+ :value => @value
23
+ }
24
+ end
25
+
26
+ 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 result()
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,45 @@
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
+ @booleans.include? value
31
+ end
32
+
33
+ def result()
34
+ {
35
+ :type => @type,
36
+ :is_true => @booleans.include?,
37
+ :is_false => @booleans.include?
38
+ }
39
+ end
40
+
41
+ def random()
42
+ @booleans.to_a.sample
43
+ end
44
+
45
+ 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