gloo 0.3.0 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.rubocop.yml +73 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +86 -83
- data/Rakefile +7 -6
- data/bin/console +4 -4
- data/gloo.gemspec +22 -18
- data/lib/gloo.rb +6 -6
- data/lib/gloo/app/args.rb +30 -31
- data/lib/gloo/app/engine.rb +80 -30
- data/lib/gloo/app/help.rb +17 -11
- data/lib/gloo/app/info.rb +3 -3
- data/lib/gloo/app/log.rb +17 -17
- data/lib/gloo/app/mode.rb +4 -4
- data/lib/gloo/app/settings.rb +51 -41
- data/lib/gloo/convert/string_to_datetime.rb +21 -0
- data/lib/gloo/convert/string_to_decimal.rb +20 -0
- data/lib/gloo/convert/string_to_integer.rb +20 -0
- data/lib/gloo/core/baseo.rb +7 -7
- data/lib/gloo/core/dictionary.rb +30 -27
- data/lib/gloo/core/error.rb +50 -0
- data/lib/gloo/core/event_manager.rb +17 -23
- data/lib/gloo/core/factory.rb +149 -39
- data/lib/gloo/core/gloo_system.rb +121 -54
- data/lib/gloo/core/heap.rb +15 -13
- data/lib/gloo/core/it.rb +5 -5
- data/lib/gloo/core/literal.rb +7 -7
- data/lib/gloo/core/obj.rb +138 -79
- data/lib/gloo/core/obj_finder.rb +9 -14
- data/lib/gloo/core/op.rb +8 -8
- data/lib/gloo/core/parser.rb +27 -26
- data/lib/gloo/core/pn.rb +68 -52
- data/lib/gloo/core/script.rb +7 -7
- data/lib/gloo/core/tokens.rb +39 -41
- data/lib/gloo/core/verb.rb +30 -19
- data/lib/gloo/exec/dispatch.rb +30 -0
- data/lib/gloo/exec/runner.rb +43 -0
- data/lib/gloo/expr/expression.rb +36 -43
- data/lib/gloo/expr/l_boolean.rb +7 -6
- data/lib/gloo/expr/l_decimal.rb +34 -0
- data/lib/gloo/expr/l_integer.rb +5 -4
- data/lib/gloo/expr/l_string.rb +13 -15
- data/lib/gloo/expr/op_div.rb +5 -5
- data/lib/gloo/expr/op_minus.rb +5 -5
- data/lib/gloo/expr/op_mult.rb +5 -5
- data/lib/gloo/expr/op_plus.rb +7 -7
- data/lib/gloo/objs/basic/alias.rb +111 -0
- data/lib/gloo/objs/basic/boolean.rb +63 -38
- data/lib/gloo/objs/basic/container.rb +71 -12
- data/lib/gloo/objs/basic/decimal.rb +96 -0
- data/lib/gloo/objs/basic/integer.rb +45 -16
- data/lib/gloo/objs/basic/script.rb +62 -38
- data/lib/gloo/objs/basic/string.rb +47 -15
- data/lib/gloo/objs/basic/text.rb +69 -21
- data/lib/gloo/objs/basic/untyped.rb +35 -10
- data/lib/gloo/objs/cli/banner.rb +137 -0
- data/lib/gloo/objs/cli/bar.rb +141 -0
- data/lib/gloo/objs/cli/colorize.rb +54 -24
- data/lib/gloo/objs/cli/confirm.rb +63 -29
- data/lib/gloo/objs/cli/menu.rb +236 -0
- data/lib/gloo/objs/cli/menu_item.rb +128 -0
- data/lib/gloo/objs/cli/pastel.rb +120 -0
- data/lib/gloo/objs/cli/prompt.rb +73 -31
- data/lib/gloo/objs/cli/select.rb +153 -0
- data/lib/gloo/objs/ctrl/each.rb +128 -61
- data/lib/gloo/objs/ctrl/repeat.rb +129 -0
- data/lib/gloo/objs/data/markdown.rb +109 -0
- data/lib/gloo/objs/data/table.rb +168 -0
- data/lib/gloo/objs/dev/git.rb +98 -64
- data/lib/gloo/objs/dt/date.rb +72 -0
- data/lib/gloo/objs/dt/datetime.rb +84 -0
- data/lib/gloo/objs/dt/time.rb +72 -0
- data/lib/gloo/objs/ror/erb.rb +82 -41
- data/lib/gloo/objs/ror/eval.rb +73 -31
- data/lib/gloo/objs/snd/play.rb +71 -0
- data/lib/gloo/objs/snd/say.rb +120 -0
- data/lib/gloo/objs/system/file_handle.rb +129 -48
- data/lib/gloo/objs/system/system.rb +84 -38
- data/lib/gloo/objs/web/http_get.rb +103 -46
- data/lib/gloo/objs/web/http_post.rb +70 -44
- data/lib/gloo/objs/web/json.rb +155 -0
- data/lib/gloo/objs/web/slack.rb +89 -58
- data/lib/gloo/objs/web/teams.rb +88 -53
- data/lib/gloo/objs/web/uri.rb +160 -0
- data/lib/gloo/persist/file_loader.rb +95 -85
- data/lib/gloo/persist/file_saver.rb +12 -12
- data/lib/gloo/persist/file_storage.rb +15 -15
- data/lib/gloo/persist/line_splitter.rb +79 -0
- data/lib/gloo/persist/persist_man.rb +63 -39
- data/lib/gloo/utils/words.rb +2 -2
- data/lib/gloo/verbs/alert.rb +67 -16
- data/lib/gloo/verbs/beep.rb +70 -0
- data/lib/gloo/verbs/cls.rb +67 -0
- data/lib/gloo/verbs/context.rb +61 -21
- data/lib/gloo/verbs/create.rb +52 -21
- data/lib/gloo/verbs/help.rb +186 -27
- data/lib/gloo/verbs/if.rb +55 -21
- data/lib/gloo/verbs/list.rb +55 -24
- data/lib/gloo/verbs/load.rb +47 -12
- data/lib/gloo/verbs/move.rb +128 -0
- data/lib/gloo/verbs/put.rb +90 -34
- data/lib/gloo/verbs/quit.rb +43 -12
- data/lib/gloo/verbs/run.rb +63 -18
- data/lib/gloo/verbs/save.rb +45 -10
- data/lib/gloo/verbs/show.rb +56 -22
- data/lib/gloo/verbs/tell.rb +45 -13
- data/lib/gloo/verbs/unless.rb +56 -21
- data/lib/gloo/verbs/version.rb +42 -12
- data/lib/gloo/verbs/wait.rb +73 -0
- data/lib/run.rb +5 -5
- metadata +90 -12
data/lib/gloo/expr/op_minus.rb
CHANGED
@@ -9,12 +9,12 @@ module Gloo
|
|
9
9
|
class OpMinus < Gloo::Core::Op
|
10
10
|
|
11
11
|
# Perform the operation and return the result.
|
12
|
-
def perform left, right
|
13
|
-
if left.is_a? Integer
|
14
|
-
|
15
|
-
|
12
|
+
def perform( left, right )
|
13
|
+
return left - right.to_i if left.is_a? Integer
|
14
|
+
|
15
|
+
return left - right.to_f if left.is_a? Numeric
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/gloo/expr/op_mult.rb
CHANGED
@@ -9,12 +9,12 @@ module Gloo
|
|
9
9
|
class OpMult < Gloo::Core::Op
|
10
10
|
|
11
11
|
# Perform the operation and return the result.
|
12
|
-
def perform left, right
|
13
|
-
if left.is_a? Integer
|
14
|
-
|
15
|
-
|
12
|
+
def perform( left, right )
|
13
|
+
return left * right.to_i if left.is_a? Integer
|
14
|
+
|
15
|
+
return left * right.to_f if left.is_a? Numeric
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/gloo/expr/op_plus.rb
CHANGED
@@ -9,14 +9,14 @@ module Gloo
|
|
9
9
|
class OpPlus < Gloo::Core::Op
|
10
10
|
|
11
11
|
# Perform the operation and return the result.
|
12
|
-
def perform left, right
|
13
|
-
if left.is_a? String
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
def perform( left, right )
|
13
|
+
return left + right.to_s if left.is_a? String
|
14
|
+
|
15
|
+
return left + right.to_i if left.is_a? Integer
|
16
|
+
|
17
|
+
return left + right.to_f if left.is_a? Numeric
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# A String.
|
5
|
+
#
|
6
|
+
|
7
|
+
module Gloo
|
8
|
+
module Objs
|
9
|
+
class Alias < Gloo::Core::Obj
|
10
|
+
|
11
|
+
KEYWORD = 'alias'.freeze
|
12
|
+
KEYWORD_SHORT = 'ln'.freeze
|
13
|
+
ALIAS_REFERENCE = '*'.freeze
|
14
|
+
|
15
|
+
#
|
16
|
+
# The name of the object type.
|
17
|
+
#
|
18
|
+
def self.typename
|
19
|
+
return KEYWORD
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# The short name of the object type.
|
24
|
+
#
|
25
|
+
def self.short_typename
|
26
|
+
return KEYWORD_SHORT
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Set the value with any necessary type conversions.
|
31
|
+
#
|
32
|
+
def set_value( new_value )
|
33
|
+
self.value = new_value.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
# ---------------------------------------------------------------------
|
37
|
+
# Messages
|
38
|
+
# ---------------------------------------------------------------------
|
39
|
+
|
40
|
+
#
|
41
|
+
# Get a list of message names that this object receives.
|
42
|
+
#
|
43
|
+
def self.messages
|
44
|
+
return super + %w[resolve]
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Check to see if the referenced object exists.
|
49
|
+
#
|
50
|
+
def msg_resolve
|
51
|
+
pn = Gloo::Core::Pn.new( self.value )
|
52
|
+
s = pn.exists?
|
53
|
+
$engine.heap.it.set_to s
|
54
|
+
return s
|
55
|
+
end
|
56
|
+
|
57
|
+
# ---------------------------------------------------------------------
|
58
|
+
# Resolve
|
59
|
+
# ---------------------------------------------------------------------
|
60
|
+
|
61
|
+
#
|
62
|
+
# Is the object an alias If so, then resolve it.
|
63
|
+
# The ref_name is the name used to refer to the object.
|
64
|
+
# If it ends with the * then we won't resolve the alias since
|
65
|
+
# we are trying to refer to the alias itself.
|
66
|
+
#
|
67
|
+
def self.resolve_alias( obj, ref_name = nil )
|
68
|
+
return nil unless obj
|
69
|
+
return obj unless obj.type_display == Gloo::Objs::Alias.typename
|
70
|
+
return obj if ref_name&.end_with?( ALIAS_REFERENCE )
|
71
|
+
|
72
|
+
ln = Gloo::Core::Pn.new( obj.value )
|
73
|
+
return ln.resolve
|
74
|
+
end
|
75
|
+
|
76
|
+
# ---------------------------------------------------------------------
|
77
|
+
# Help
|
78
|
+
# ---------------------------------------------------------------------
|
79
|
+
|
80
|
+
#
|
81
|
+
# Get help for this object type.
|
82
|
+
#
|
83
|
+
def self.help
|
84
|
+
return <<~TEXT
|
85
|
+
ALIAS OBJECT TYPE
|
86
|
+
NAME: alias
|
87
|
+
SHORTCUT: ln
|
88
|
+
|
89
|
+
DESCRIPTION
|
90
|
+
A pointer to another object.
|
91
|
+
Normal path-name references will refere to the aliased object.
|
92
|
+
To refer to the alias itself, add an * at the end of the path-name.
|
93
|
+
This is neeed, for example, to set the value of the alias.
|
94
|
+
The value of the alias is merely the path-name of the
|
95
|
+
referenced object.
|
96
|
+
|
97
|
+
CHILDREN
|
98
|
+
None
|
99
|
+
|
100
|
+
MESSAGES
|
101
|
+
The alias will reflect the mesages of the object to which
|
102
|
+
it points.
|
103
|
+
The alias itself can receive the following message:
|
104
|
+
resolve - Check to see if the object referenced exists.
|
105
|
+
Sets it to true or false.
|
106
|
+
TEXT
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -7,88 +7,86 @@
|
|
7
7
|
module Gloo
|
8
8
|
module Objs
|
9
9
|
class Boolean < Gloo::Core::Obj
|
10
|
-
|
11
|
-
KEYWORD = 'boolean'
|
12
|
-
KEYWORD_SHORT = 'bool'
|
13
|
-
TRUE = 'true'
|
14
|
-
FALSE = 'false'
|
15
10
|
|
16
|
-
|
11
|
+
KEYWORD = 'boolean'.freeze
|
12
|
+
KEYWORD_SHORT = 'bool'.freeze
|
13
|
+
TRUE = 'true'.freeze
|
14
|
+
FALSE = 'false'.freeze
|
15
|
+
|
16
|
+
#
|
17
17
|
# The name of the object type.
|
18
|
-
#
|
18
|
+
#
|
19
19
|
def self.typename
|
20
20
|
return KEYWORD
|
21
21
|
end
|
22
22
|
|
23
|
-
#
|
23
|
+
#
|
24
24
|
# The short name of the object type.
|
25
|
-
#
|
25
|
+
#
|
26
26
|
def self.short_typename
|
27
27
|
return KEYWORD_SHORT
|
28
28
|
end
|
29
29
|
|
30
|
-
#
|
30
|
+
#
|
31
31
|
# Set the value with any necessary type conversions.
|
32
|
-
#
|
33
|
-
def set_value new_value
|
32
|
+
#
|
33
|
+
def set_value( new_value )
|
34
34
|
self.value = Gloo::Objs::Boolean.coerse_to_bool( new_value )
|
35
35
|
end
|
36
|
-
|
37
|
-
#
|
36
|
+
|
37
|
+
#
|
38
38
|
# Coerse the new value to a boolean value.
|
39
|
-
#
|
40
|
-
def self.coerse_to_bool new_value
|
41
|
-
if new_value.nil?
|
42
|
-
|
43
|
-
|
39
|
+
#
|
40
|
+
def self.coerse_to_bool( new_value )
|
41
|
+
return false if new_value.nil?
|
42
|
+
|
43
|
+
if new_value.class.name == 'String'
|
44
44
|
return true if new_value.strip.downcase == TRUE
|
45
45
|
return false if new_value.strip.downcase == FALSE
|
46
46
|
return true if new_value.strip.downcase == 't'
|
47
47
|
return false if new_value.strip.downcase == 'f'
|
48
|
-
elsif new_value.class.name ==
|
49
|
-
return
|
50
|
-
return true
|
51
|
-
else
|
52
|
-
return new_value == true
|
48
|
+
elsif new_value.class.name == 'Integer'
|
49
|
+
return new_value.zero? ? false : true
|
53
50
|
end
|
51
|
+
|
52
|
+
return new_value == true
|
54
53
|
end
|
55
|
-
|
56
|
-
#
|
54
|
+
|
55
|
+
#
|
57
56
|
# Is the given token a boolean?
|
58
|
-
#
|
59
|
-
def self.
|
57
|
+
#
|
58
|
+
def self.boolean?( token )
|
60
59
|
return true if token == true
|
61
60
|
return true if token == false
|
62
|
-
|
61
|
+
|
62
|
+
if token.class.name == 'String'
|
63
63
|
return true if token.strip.downcase == TRUE
|
64
64
|
return true if token.strip.downcase == FALSE
|
65
65
|
end
|
66
66
|
return false
|
67
67
|
end
|
68
68
|
|
69
|
-
|
70
|
-
#
|
69
|
+
#
|
71
70
|
# Get the value for display purposes.
|
72
|
-
#
|
71
|
+
#
|
73
72
|
def value_display
|
74
73
|
return value ? TRUE : FALSE
|
75
74
|
end
|
76
75
|
|
77
|
-
|
78
76
|
# ---------------------------------------------------------------------
|
79
77
|
# Messages
|
80
78
|
# ---------------------------------------------------------------------
|
81
79
|
|
82
|
-
#
|
80
|
+
#
|
83
81
|
# Get a list of message names that this object receives.
|
84
|
-
#
|
82
|
+
#
|
85
83
|
def self.messages
|
86
|
-
return super + [
|
84
|
+
return super + %w[not true false]
|
87
85
|
end
|
88
|
-
|
86
|
+
|
89
87
|
# Set the value to the opposite of what it is.
|
90
88
|
def msg_not
|
91
|
-
v = !
|
89
|
+
v = !value
|
92
90
|
set_value v
|
93
91
|
$engine.heap.it.set_to v
|
94
92
|
return v
|
@@ -108,6 +106,33 @@ module Gloo
|
|
108
106
|
return false
|
109
107
|
end
|
110
108
|
|
109
|
+
# ---------------------------------------------------------------------
|
110
|
+
# Help
|
111
|
+
# ---------------------------------------------------------------------
|
112
|
+
|
113
|
+
#
|
114
|
+
# Get help for this object type.
|
115
|
+
#
|
116
|
+
def self.help
|
117
|
+
return <<~TEXT
|
118
|
+
BOOLEAN OBJECT TYPE
|
119
|
+
NAME: boolean
|
120
|
+
SHORTCUT: bool
|
121
|
+
|
122
|
+
DESCRIPTION
|
123
|
+
A boolean value.
|
124
|
+
Value will be either true or false.
|
125
|
+
|
126
|
+
CHILDREN
|
127
|
+
None
|
128
|
+
|
129
|
+
MESSAGES
|
130
|
+
not - Set the boolean to the opposite of what it is now.
|
131
|
+
true - Set the boolean to true.
|
132
|
+
false - Set the boolean to false.
|
133
|
+
TEXT
|
134
|
+
end
|
135
|
+
|
111
136
|
end
|
112
137
|
end
|
113
138
|
end
|
@@ -3,47 +3,106 @@
|
|
3
3
|
#
|
4
4
|
# An object that contains a collection of other objects.
|
5
5
|
#
|
6
|
+
require 'tty-table'
|
7
|
+
require 'pastel'
|
6
8
|
|
7
9
|
module Gloo
|
8
10
|
module Objs
|
9
11
|
class Container < Gloo::Core::Obj
|
10
|
-
|
11
|
-
KEYWORD = 'container'
|
12
|
-
KEYWORD_SHORT = 'can'
|
13
12
|
|
14
|
-
|
13
|
+
KEYWORD = 'container'.freeze
|
14
|
+
KEYWORD_SHORT = 'can'.freeze
|
15
|
+
|
16
|
+
#
|
15
17
|
# The name of the object type.
|
16
|
-
#
|
18
|
+
#
|
17
19
|
def self.typename
|
18
20
|
return KEYWORD
|
19
21
|
end
|
20
22
|
|
21
|
-
#
|
23
|
+
#
|
22
24
|
# The short name of the object type.
|
23
|
-
#
|
25
|
+
#
|
24
26
|
def self.short_typename
|
25
27
|
return KEYWORD_SHORT
|
26
28
|
end
|
27
29
|
|
28
|
-
|
29
30
|
# ---------------------------------------------------------------------
|
30
31
|
# Messages
|
31
32
|
# ---------------------------------------------------------------------
|
32
33
|
|
33
|
-
#
|
34
|
+
#
|
34
35
|
# Get a list of message names that this object receives.
|
35
|
-
#
|
36
|
+
#
|
36
37
|
def self.messages
|
37
|
-
return super + [
|
38
|
+
return super + %w[count delete_children show_key_value_table]
|
38
39
|
end
|
39
|
-
|
40
|
+
|
41
|
+
#
|
40
42
|
# Count the number of children in the container.
|
43
|
+
#
|
41
44
|
def msg_count
|
42
45
|
i = child_count
|
43
46
|
$engine.heap.it.set_to i
|
44
47
|
return i
|
45
48
|
end
|
46
49
|
|
50
|
+
#
|
51
|
+
# Delete all children in the container.
|
52
|
+
#
|
53
|
+
def msg_delete_children
|
54
|
+
self.delete_children
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# Show the given table data.
|
59
|
+
#
|
60
|
+
def msg_show_key_value_table
|
61
|
+
data = self.children.map { |o| [ o.name, o.value ] }
|
62
|
+
pastel = ::Pastel.new
|
63
|
+
table = TTY::Table.new rows: data
|
64
|
+
pad = [ 0, 1, 0, 1 ]
|
65
|
+
rendered = table.render( :ascii, indent: 2, padding: pad ) do |r|
|
66
|
+
r.border.style = :blue
|
67
|
+
r.filter = proc do |val, _row_index, col_index|
|
68
|
+
col_index.zero? ? pastel.blue( val ) : pastel.white( val )
|
69
|
+
end
|
70
|
+
end
|
71
|
+
puts "\n #{rendered}\n\n"
|
72
|
+
end
|
73
|
+
|
74
|
+
# ---------------------------------------------------------------------
|
75
|
+
# Help
|
76
|
+
# ---------------------------------------------------------------------
|
77
|
+
|
78
|
+
#
|
79
|
+
# Get help for this object type.
|
80
|
+
#
|
81
|
+
def self.help
|
82
|
+
return <<~TEXT
|
83
|
+
CONTAINER OBJECT TYPE
|
84
|
+
NAME: container
|
85
|
+
SHORTCUT: can
|
86
|
+
|
87
|
+
DESCRIPTION
|
88
|
+
A container of other objects.
|
89
|
+
A container is similar to a folder in a file system.
|
90
|
+
It can contain any number of objects including other containers.
|
91
|
+
The container structure provides direct access to any object
|
92
|
+
within it through the object.object.object path-name structure.
|
93
|
+
|
94
|
+
CHILDREN
|
95
|
+
None by default. But any container can have any number of
|
96
|
+
objects added to it.
|
97
|
+
|
98
|
+
MESSAGES
|
99
|
+
count - Count the number of children objects in the container.
|
100
|
+
The result is put in <it>.
|
101
|
+
delete_children - Delete all children objects from the container.
|
102
|
+
show_key_value_tbl - Show a table with key (name) and values
|
103
|
+
for all children in the container.
|
104
|
+
TEXT
|
105
|
+
end
|
47
106
|
|
48
107
|
end
|
49
108
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# An object with a decimal value.
|
5
|
+
#
|
6
|
+
|
7
|
+
module Gloo
|
8
|
+
module Objs
|
9
|
+
class Decimal < Gloo::Core::Obj
|
10
|
+
|
11
|
+
KEYWORD = 'decimal'.freeze
|
12
|
+
KEYWORD_SHORT = 'num'.freeze
|
13
|
+
|
14
|
+
#
|
15
|
+
# The name of the object type.
|
16
|
+
#
|
17
|
+
def self.typename
|
18
|
+
return KEYWORD
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# The short name of the object type.
|
23
|
+
#
|
24
|
+
def self.short_typename
|
25
|
+
return KEYWORD_SHORT
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Set the value with any necessary type conversions.
|
30
|
+
#
|
31
|
+
def set_value( new_value )
|
32
|
+
if new_value.nil?
|
33
|
+
self.value = 0.0
|
34
|
+
return
|
35
|
+
end
|
36
|
+
|
37
|
+
unless new_value.is_a? Numeric
|
38
|
+
self.value = $engine.convert( new_value, 'Decimal', 0.0 )
|
39
|
+
return
|
40
|
+
end
|
41
|
+
|
42
|
+
self.value = new_value.to_f
|
43
|
+
end
|
44
|
+
|
45
|
+
# ---------------------------------------------------------------------
|
46
|
+
# Messages
|
47
|
+
# ---------------------------------------------------------------------
|
48
|
+
|
49
|
+
#
|
50
|
+
# Get a list of message names that this object receives.
|
51
|
+
#
|
52
|
+
def self.messages
|
53
|
+
return super + %w[round]
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# Round the value to a whole value.
|
58
|
+
# If a parameter is included in the message,
|
59
|
+
# round to the precision given.
|
60
|
+
#
|
61
|
+
def msg_round
|
62
|
+
i = value + 1
|
63
|
+
set_value i
|
64
|
+
$engine.heap.it.set_to i
|
65
|
+
return i
|
66
|
+
end
|
67
|
+
|
68
|
+
# ---------------------------------------------------------------------
|
69
|
+
# Help
|
70
|
+
# ---------------------------------------------------------------------
|
71
|
+
|
72
|
+
#
|
73
|
+
# Get help for this object type.
|
74
|
+
#
|
75
|
+
def self.help
|
76
|
+
return <<~TEXT
|
77
|
+
DECIMAL OBJECT TYPE
|
78
|
+
NAME: decimal
|
79
|
+
SHORTCUT: num
|
80
|
+
|
81
|
+
DESCRIPTION
|
82
|
+
A decimal (numeric) value.
|
83
|
+
|
84
|
+
CHILDREN
|
85
|
+
None
|
86
|
+
|
87
|
+
MESSAGES
|
88
|
+
round - Round to the nearest whole value.
|
89
|
+
If an optional parameter is included, round to the
|
90
|
+
precision specified.
|
91
|
+
TEXT
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|