fat_core 1.7.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,43 +0,0 @@
1
- module FatCore
2
- # The Evaluator class provides a class for evaluating Ruby expressions based
3
- # on variable settings provided at runtime. If the same Evaluator object is
4
- # used for several successive calls, it can maintain state between calls with
5
- # instance variables. The call to Evaluator.new can be given a hash of
6
- # instance variable names and values that will be maintained across all calls
7
- # to the #evaluate method. In addition, on each evaluate call, a set of
8
- # /local/ variables can be supplied to provide variables that exist only for
9
- # the duration of that evaluate call. An optional before and after string can
10
- # be given to the constructor that will evaluate the given expression before
11
- # and, respectively, after each call to #evaluate. This provides a way to
12
- # update values of instance variables for use in subsequent calls to
13
- # #evaluate.
14
- class Evaluator
15
- def initialize(vars: {}, before: nil, after: nil)
16
- @before = before
17
- @after = after
18
- set_instance_vars(vars)
19
- end
20
-
21
- def set_instance_vars(vars = {})
22
- vars.each_pair do |name, val|
23
- name = "@#{name}" unless name.to_s.start_with?('@')
24
- instance_variable_set(name, val)
25
- end
26
- end
27
-
28
- def set_local_vars(vars = {}, bnd)
29
- vars.each_pair do |name, val|
30
- bnd.local_variable_set(name, val)
31
- end
32
- end
33
-
34
- def evaluate(expr = '', vars: {})
35
- bdg = binding
36
- set_local_vars(vars, bdg)
37
- eval(@before, bdg) if @before
38
- result = eval(expr, bdg)
39
- eval(@after, bdg) if @after
40
- result
41
- end
42
- end
43
- end
@@ -1,84 +0,0 @@
1
- module FatCore
2
- class AoaFormatter < Formatter
3
- def evaluate?
4
- true
5
- end
6
-
7
- def pre_table
8
- '['
9
- end
10
-
11
- def post_table
12
- ']'
13
- end
14
-
15
- def pre_header(_widths)
16
- ''
17
- end
18
-
19
- def post_header(_widths)
20
- ''
21
- end
22
-
23
- def pre_row
24
- '['
25
- end
26
-
27
- def pre_cell(_h)
28
- "'"
29
- end
30
-
31
- # Because the cell, after conversion to a single-quoted string will be
32
- # eval'ed, we need to escape any single-quotes (') that appear in the
33
- # string.
34
- def quote_cell(v)
35
- if v =~ /'/
36
- # Use a negative look-behind to only quote single-quotes that are not
37
- # already preceded by a backslash
38
- v.gsub(/(?<!\\)'/, "'" => "\\'")
39
- else
40
- v
41
- end
42
- end
43
-
44
- def post_cell
45
- "'"
46
- end
47
-
48
- def inter_cell
49
- ','
50
- end
51
-
52
- def post_row
53
- "],\n"
54
- end
55
-
56
- def hline(_widths)
57
- "nil,\n"
58
- end
59
-
60
- def pre_group
61
- ''
62
- end
63
-
64
- def post_group
65
- ''
66
- end
67
-
68
- def pre_gfoot
69
- ''
70
- end
71
-
72
- def post_gfoot
73
- ''
74
- end
75
-
76
- def pre_foot
77
- ''
78
- end
79
-
80
- def post_foot
81
- ''
82
- end
83
- end
84
- end
@@ -1,82 +0,0 @@
1
- module FatCore
2
- class AohFormatter < Formatter
3
- def evaluate?
4
- true
5
- end
6
-
7
- def pre_table
8
- '['
9
- end
10
-
11
- def post_table
12
- ']'
13
- end
14
-
15
- # We include no row for the header because the keys of each hash serve as
16
- # the headers.
17
- def include_header_row?
18
- false
19
- end
20
-
21
- def pre_row
22
- '{'
23
- end
24
-
25
- def pre_cell(h)
26
- ":#{h.as_sym} => '"
27
- end
28
-
29
- # Because the cell, after conversion to a single-quoted string will be
30
- # eval'ed, we need to escape any single-quotes (') that appear in the
31
- # string.
32
- def quote_cell(v)
33
- if v =~ /'/
34
- # Use a negative look-behind to only quote single-quotes that are not
35
- # already preceded by a backslash
36
- v.gsub(/(?<!\\)'/, "'" => "\\'")
37
- else
38
- v
39
- end
40
- end
41
-
42
- def post_cell
43
- "'"
44
- end
45
-
46
- def inter_cell
47
- ','
48
- end
49
-
50
- def post_row
51
- "},\n"
52
- end
53
-
54
- def hline(_widths)
55
- "nil,\n"
56
- end
57
-
58
- def pre_group
59
- ''
60
- end
61
-
62
- def post_group
63
- ''
64
- end
65
-
66
- def pre_gfoot
67
- ''
68
- end
69
-
70
- def post_gfoot
71
- ''
72
- end
73
-
74
- def pre_foot
75
- ''
76
- end
77
-
78
- def post_foot
79
- ''
80
- end
81
- end
82
- end