gloo-lang 1.3.1 → 1.4.0
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.
- checksums.yaml +4 -4
- data/lib/VERSION +1 -1
- data/lib/gloo_lang/convert/string_to_date.rb +21 -0
- data/lib/gloo_lang/convert/string_to_time.rb +21 -0
- data/lib/gloo_lang/core/pn.rb +20 -0
- data/lib/gloo_lang/objs/dt/date.rb +18 -3
- data/lib/gloo_lang/objs/dt/datetime.rb +66 -8
- data/lib/gloo_lang/objs/dt/dt_tools.rb +100 -0
- data/lib/gloo_lang/objs/dt/time.rb +18 -3
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d531b63b5915a6b08b376c0363e3077df486261991e3db9b505ff141d1245b64
|
4
|
+
data.tar.gz: f2b6bc778beac2fe00e846ea85376b2519e21cd824036ca18832592c134add90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 888622b3913bff08e64a3621c93d1af29bd73076992bc50de1cc39daf2b925744c66ceaf2ef1b3eb67ffa780c93a7b50ae9c2a3e768127756a33a996b67d2789
|
7
|
+
data.tar.gz: c5c0a5bdb099ad613d7e70367ecd320a428e2b129c70fe75472ea5779170e91181fecf81245ae294a04a561b2425ceb5ad782c5630682ff629d5d1075aed43d8
|
data/lib/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2023 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# Conversion tool: String to Date.
|
5
|
+
#
|
6
|
+
require 'chronic'
|
7
|
+
|
8
|
+
module GlooLang
|
9
|
+
module Convert
|
10
|
+
class StringToDate
|
11
|
+
|
12
|
+
#
|
13
|
+
# Convert the given string value to date.
|
14
|
+
#
|
15
|
+
def convert( value )
|
16
|
+
return Chronic.parse( value )
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2023 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# Conversion tool: String to Time.
|
5
|
+
#
|
6
|
+
require 'chronic'
|
7
|
+
|
8
|
+
module GlooLang
|
9
|
+
module Convert
|
10
|
+
class StringToTime
|
11
|
+
|
12
|
+
#
|
13
|
+
# Convert the given string value to time.
|
14
|
+
#
|
15
|
+
def convert( value )
|
16
|
+
return Chronic.parse( value )
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/gloo_lang/core/pn.rb
CHANGED
@@ -12,6 +12,7 @@ module GlooLang
|
|
12
12
|
ROOT = 'root'.freeze
|
13
13
|
IT = 'it'.freeze
|
14
14
|
ERROR = 'error'.freeze
|
15
|
+
CONTEXT = '@'.freeze
|
15
16
|
|
16
17
|
attr_reader :src, :elements
|
17
18
|
|
@@ -124,6 +125,21 @@ module GlooLang
|
|
124
125
|
return @elements.count > 1
|
125
126
|
end
|
126
127
|
|
128
|
+
#
|
129
|
+
# Does the path start with the context?
|
130
|
+
#
|
131
|
+
def includes_context?
|
132
|
+
return @src.start_with?( "#{CONTEXT}." )
|
133
|
+
end
|
134
|
+
|
135
|
+
#
|
136
|
+
# Expand the context so we have the full path.
|
137
|
+
#
|
138
|
+
def expand_context
|
139
|
+
# return unless @engine.heap.context
|
140
|
+
self.set_to( "#{@engine.heap.context}#{@src[1..-1]}" )
|
141
|
+
end
|
142
|
+
|
127
143
|
#
|
128
144
|
# Get the parent that contains the object referenced.
|
129
145
|
#
|
@@ -180,6 +196,10 @@ module GlooLang
|
|
180
196
|
Here.expand_here( @engine, self )
|
181
197
|
end
|
182
198
|
|
199
|
+
if self.includes_context?
|
200
|
+
expand_context
|
201
|
+
end
|
202
|
+
|
183
203
|
parent = self.get_parent
|
184
204
|
return nil unless parent
|
185
205
|
|
@@ -10,6 +10,7 @@ module GlooLang
|
|
10
10
|
|
11
11
|
KEYWORD = 'date'.freeze
|
12
12
|
KEYWORD_SHORT = 'date'.freeze
|
13
|
+
DEFAULT_FORMAT = '%Y.%m.%d'.freeze
|
13
14
|
|
14
15
|
#
|
15
16
|
# The name of the object type.
|
@@ -25,6 +26,21 @@ module GlooLang
|
|
25
26
|
return KEYWORD_SHORT
|
26
27
|
end
|
27
28
|
|
29
|
+
#
|
30
|
+
# Set the value with any necessary type conversions.
|
31
|
+
#
|
32
|
+
def set_value( new_value )
|
33
|
+
if DtTools.is_dt_type? new_value
|
34
|
+
self.value = new_value
|
35
|
+
else
|
36
|
+
self.value = @engine.converter.convert( new_value, 'Date', nil )
|
37
|
+
end
|
38
|
+
|
39
|
+
if DtTools.is_dt_type? self.value
|
40
|
+
self.value = self.value.strftime( DEFAULT_FORMAT )
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
28
44
|
# ---------------------------------------------------------------------
|
29
45
|
# Messages
|
30
46
|
# ---------------------------------------------------------------------
|
@@ -40,9 +56,8 @@ module GlooLang
|
|
40
56
|
# Set to the current date.
|
41
57
|
#
|
42
58
|
def msg_now
|
43
|
-
|
44
|
-
self.value
|
45
|
-
@engine.heap.it.set_to t
|
59
|
+
self.set_value( DateTime.now )
|
60
|
+
@engine.heap.it.set_to self.value
|
46
61
|
end
|
47
62
|
|
48
63
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# A Date and Time object.
|
5
5
|
#
|
6
|
+
require 'active_support/all'
|
6
7
|
|
7
8
|
module GlooLang
|
8
9
|
module Objs
|
@@ -10,6 +11,7 @@ module GlooLang
|
|
10
11
|
|
11
12
|
KEYWORD = 'datetime'.freeze
|
12
13
|
KEYWORD_SHORT = 'dt'.freeze
|
14
|
+
DEFAULT_FORMAT = '%Y.%m.%d %I:%M:%S %P'.freeze
|
13
15
|
|
14
16
|
#
|
15
17
|
# The name of the object type.
|
@@ -29,14 +31,17 @@ module GlooLang
|
|
29
31
|
# Set the value with any necessary type conversions.
|
30
32
|
#
|
31
33
|
def set_value( new_value )
|
32
|
-
|
34
|
+
if DtTools.is_dt_type? new_value
|
35
|
+
self.value = new_value
|
36
|
+
else
|
33
37
|
self.value = @engine.converter.convert( new_value, 'DateTime', nil )
|
34
|
-
return
|
35
38
|
end
|
36
39
|
|
37
|
-
self.value
|
40
|
+
if DtTools.is_dt_type? self.value
|
41
|
+
self.value = self.value.strftime( DEFAULT_FORMAT )
|
42
|
+
end
|
38
43
|
end
|
39
|
-
|
44
|
+
|
40
45
|
# ---------------------------------------------------------------------
|
41
46
|
# Messages
|
42
47
|
# ---------------------------------------------------------------------
|
@@ -45,16 +50,69 @@ module GlooLang
|
|
45
50
|
# Get a list of message names that this object receives.
|
46
51
|
#
|
47
52
|
def self.messages
|
48
|
-
return super + %w[now]
|
53
|
+
return super + %w[now is_today is_future is_past is_yesterday is_tomorrow is_this_week]
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# Tell the datetime to check if it is today.
|
58
|
+
#
|
59
|
+
def msg_is_today
|
60
|
+
today = DtTools.is_today?( self.value )
|
61
|
+
@engine.heap.it.set_to today
|
62
|
+
return today
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# Tell the datetime to check if it is in the future.
|
67
|
+
#
|
68
|
+
def msg_is_future
|
69
|
+
today = DtTools.is_future?( self.value )
|
70
|
+
@engine.heap.it.set_to today
|
71
|
+
return today
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# Tell the datetime to check if it is in the past.
|
76
|
+
#
|
77
|
+
def msg_is_past
|
78
|
+
today = DtTools.is_past?( self.value )
|
79
|
+
@engine.heap.it.set_to today
|
80
|
+
return today
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# Tell the datetime to check if it is yesterday.
|
85
|
+
#
|
86
|
+
def msg_is_yesterday
|
87
|
+
today = DtTools.is_yesterday?( self.value )
|
88
|
+
@engine.heap.it.set_to today
|
89
|
+
return today
|
90
|
+
end
|
91
|
+
|
92
|
+
#
|
93
|
+
# Tell the datetime to check if it is tomorrow.
|
94
|
+
#
|
95
|
+
def msg_is_tomorrow
|
96
|
+
today = DtTools.is_tomorrow?( self.value )
|
97
|
+
@engine.heap.it.set_to today
|
98
|
+
return today
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Tell the datetime to check if it is this week.
|
103
|
+
#
|
104
|
+
def msg_is_this_week
|
105
|
+
today = DtTools.is_this_week?( self.value )
|
106
|
+
@engine.heap.it.set_to today
|
107
|
+
return today
|
49
108
|
end
|
50
109
|
|
51
110
|
#
|
52
111
|
# Set to the current date and time.
|
53
112
|
#
|
54
113
|
def msg_now
|
55
|
-
|
56
|
-
self.value
|
57
|
-
@engine.heap.it.set_to t
|
114
|
+
self.set_value( DateTime.now )
|
115
|
+
@engine.heap.it.set_to self.value
|
58
116
|
end
|
59
117
|
|
60
118
|
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# A Date and Time object.
|
5
|
+
#
|
6
|
+
|
7
|
+
class DtTools
|
8
|
+
|
9
|
+
# ---------------------------------------------------------------------
|
10
|
+
# Type helpers
|
11
|
+
# ---------------------------------------------------------------------
|
12
|
+
|
13
|
+
#
|
14
|
+
# Is the given object a base Date Time object?
|
15
|
+
# True for DateTime and Time
|
16
|
+
#
|
17
|
+
def self.is_dt_type? obj
|
18
|
+
return true if obj.is_a? ::DateTime
|
19
|
+
return true if obj.is_a? ::Time
|
20
|
+
return false
|
21
|
+
end
|
22
|
+
|
23
|
+
# ---------------------------------------------------------------------
|
24
|
+
# Language helpers
|
25
|
+
# ---------------------------------------------------------------------
|
26
|
+
|
27
|
+
#
|
28
|
+
# Get the beginning of the week.
|
29
|
+
#
|
30
|
+
def self.beginning_of_week
|
31
|
+
return Time.now.beginning_of_week( start_day = :sunday )
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# Is the date in the next 10 days?
|
36
|
+
#
|
37
|
+
def self.in_next_ten_days?( dt )
|
38
|
+
return false if DtTools.is_past?( dt )
|
39
|
+
dt < 10.days.from_now.end_of_day
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Is the date in the past?
|
44
|
+
#
|
45
|
+
def self.is_past?( dt )
|
46
|
+
dt < Time.now.beginning_of_day
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Is the date in the future?
|
51
|
+
#
|
52
|
+
def self.is_future?( dt )
|
53
|
+
dt > Time.now.end_of_day
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# Is the given date today?
|
58
|
+
#
|
59
|
+
def self.is_today?( dt )
|
60
|
+
return false if dt.blank?
|
61
|
+
dt = Chronic.parse( dt ) if dt.is_a? String
|
62
|
+
return false if dt <= ::Time.now.beginning_of_day
|
63
|
+
return false if dt >= ::Time.now.end_of_day
|
64
|
+
return true
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Is the given date tomorrow?
|
69
|
+
#
|
70
|
+
def self.is_tomorrow?( dt )
|
71
|
+
return false if dt.blank?
|
72
|
+
dt = Chronic.parse( dt ) if dt.is_a? String
|
73
|
+
return false if dt <= ( ::Time.now.beginning_of_day + 1.day )
|
74
|
+
return false if dt >= ( ::Time.now.end_of_day + 1.day )
|
75
|
+
return true
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# Is the given date yesterday?
|
80
|
+
#
|
81
|
+
def self.is_yesterday?( dt )
|
82
|
+
return false if dt.blank?
|
83
|
+
dt = Chronic.parse( dt ) if dt.is_a? String
|
84
|
+
return false if dt <= ( ::Time.now.beginning_of_day - 1.day )
|
85
|
+
return false if dt >= ( ::Time.now.end_of_day - 1.day )
|
86
|
+
return true
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Is the given date this week?
|
91
|
+
#
|
92
|
+
def self.is_this_week?( dt )
|
93
|
+
return false if dt.blank?
|
94
|
+
dt = Chronic.parse( dt ) if dt.is_a?( String )
|
95
|
+
return false if dt <= ::Time.now.beginning_of_week( start_day = :sunday )
|
96
|
+
return false if dt >= ::Time.now.end_of_week( start_day = :sunday )
|
97
|
+
return true
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
@@ -10,6 +10,7 @@ module GlooLang
|
|
10
10
|
|
11
11
|
KEYWORD = 'time'.freeze
|
12
12
|
KEYWORD_SHORT = 'time'.freeze
|
13
|
+
DEFAULT_FORMAT = '%I:%M:%S %P'.freeze
|
13
14
|
|
14
15
|
#
|
15
16
|
# The name of the object type.
|
@@ -25,6 +26,21 @@ module GlooLang
|
|
25
26
|
return KEYWORD_SHORT
|
26
27
|
end
|
27
28
|
|
29
|
+
#
|
30
|
+
# Set the value with any necessary type conversions.
|
31
|
+
#
|
32
|
+
def set_value( new_value )
|
33
|
+
if DtTools.is_dt_type? new_value
|
34
|
+
self.value = new_value
|
35
|
+
else
|
36
|
+
self.value = @engine.converter.convert( new_value, 'Time', nil )
|
37
|
+
end
|
38
|
+
|
39
|
+
if DtTools.is_dt_type? self.value
|
40
|
+
self.value = self.value.strftime( DEFAULT_FORMAT )
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
28
44
|
# ---------------------------------------------------------------------
|
29
45
|
# Messages
|
30
46
|
# ---------------------------------------------------------------------
|
@@ -40,9 +56,8 @@ module GlooLang
|
|
40
56
|
# Set to the current time.
|
41
57
|
#
|
42
58
|
def msg_now
|
43
|
-
|
44
|
-
self.value
|
45
|
-
@engine.heap.it.set_to t
|
59
|
+
self.set_value( DateTime.now )
|
60
|
+
@engine.heap.it.set_to self.value
|
46
61
|
end
|
47
62
|
|
48
63
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gloo-lang
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Crane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -214,9 +214,11 @@ files:
|
|
214
214
|
- lib/gloo_lang/app/platform.rb
|
215
215
|
- lib/gloo_lang/app/settings.rb
|
216
216
|
- lib/gloo_lang/convert/converter.rb
|
217
|
+
- lib/gloo_lang/convert/string_to_date.rb
|
217
218
|
- lib/gloo_lang/convert/string_to_datetime.rb
|
218
219
|
- lib/gloo_lang/convert/string_to_decimal.rb
|
219
220
|
- lib/gloo_lang/convert/string_to_integer.rb
|
221
|
+
- lib/gloo_lang/convert/string_to_time.rb
|
220
222
|
- lib/gloo_lang/core/baseo.rb
|
221
223
|
- lib/gloo_lang/core/dictionary.rb
|
222
224
|
- lib/gloo_lang/core/error.rb
|
@@ -264,6 +266,7 @@ files:
|
|
264
266
|
- lib/gloo_lang/objs/data/table.rb
|
265
267
|
- lib/gloo_lang/objs/dt/date.rb
|
266
268
|
- lib/gloo_lang/objs/dt/datetime.rb
|
269
|
+
- lib/gloo_lang/objs/dt/dt_tools.rb
|
267
270
|
- lib/gloo_lang/objs/dt/time.rb
|
268
271
|
- lib/gloo_lang/objs/ror/erb.rb
|
269
272
|
- lib/gloo_lang/objs/ror/eval.rb
|