code-ruby 5.0.4 → 5.0.5
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/VERSION +1 -1
- data/lib/code/object/global.rb +77 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2a357d174303776eaab433e14c7a885a4490abb35bc7c64eeffa8fb1ca61e990
|
|
4
|
+
data.tar.gz: 1d024540aaabdffe957c6a565f94e52d8bdfbfa57635bb4d9062eb8873534906
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8e73ccd87a9fa3f1994b0b11bd9db954950671458fb77d88db349bebb775bc3e3b39eeb9fce5b87872cadbeb18454838f55200da9b3e938777952b49e45b63ed
|
|
7
|
+
data.tar.gz: 9661ddad724eeb12de32f4af27b356591d8213d7f39db172e4a6628ae5b762122601ad4e876d00cf7bac8c4e55dbb8c9414239ea8213fe1a5924d8922f1e2bad
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
5.0.
|
|
1
|
+
5.0.5
|
data/lib/code/object/global.rb
CHANGED
|
@@ -90,6 +90,15 @@ class Code
|
|
|
90
90
|
"run bin/code 'List.instance_functions.keys'"
|
|
91
91
|
]
|
|
92
92
|
}.freeze
|
|
93
|
+
WAIT_UNIT_SECONDS = {
|
|
94
|
+
milliseconds: 0.001,
|
|
95
|
+
seconds: 1,
|
|
96
|
+
minutes: ::ActiveSupport::Duration::SECONDS_PER_MINUTE,
|
|
97
|
+
hours: ::ActiveSupport::Duration::SECONDS_PER_HOUR,
|
|
98
|
+
days: ::ActiveSupport::Duration::SECONDS_PER_DAY,
|
|
99
|
+
months: ::ActiveSupport::Duration::SECONDS_PER_MONTH,
|
|
100
|
+
years: ::ActiveSupport::Duration::SECONDS_PER_YEAR
|
|
101
|
+
}.freeze
|
|
93
102
|
FUNCTIONS = {
|
|
94
103
|
"Base64" => {
|
|
95
104
|
name: "Base64",
|
|
@@ -362,6 +371,16 @@ class Code
|
|
|
362
371
|
"writes values to error with newlines and returns nothing.",
|
|
363
372
|
examples: ["warn(:hello)", "warn(1, 2)", "warn(\"hello\")"]
|
|
364
373
|
},
|
|
374
|
+
"wait" => {
|
|
375
|
+
name: "wait",
|
|
376
|
+
description:
|
|
377
|
+
"waits for the combined duration, defaulting to one second, and returns nothing.",
|
|
378
|
+
examples: [
|
|
379
|
+
"wait(milliseconds: 0)",
|
|
380
|
+
"wait(seconds: 0, minutes: 0)",
|
|
381
|
+
"wait(hours: 0, days: 0, months: 0, years: 0)"
|
|
382
|
+
]
|
|
383
|
+
},
|
|
365
384
|
"read" => {
|
|
366
385
|
name: "read",
|
|
367
386
|
description: "reads one line from input.",
|
|
@@ -662,6 +681,32 @@ class Code
|
|
|
662
681
|
sig(args) { Object.repeat }
|
|
663
682
|
args.fetch(:error).puts(*code_arguments.raw)
|
|
664
683
|
Nothing.new
|
|
684
|
+
when "wait"
|
|
685
|
+
sig(args) do
|
|
686
|
+
{
|
|
687
|
+
milliseconds: Number.maybe,
|
|
688
|
+
seconds: Number.maybe,
|
|
689
|
+
minutes: Number.maybe,
|
|
690
|
+
hours: Number.maybe,
|
|
691
|
+
days: Number.maybe,
|
|
692
|
+
months: Number.maybe,
|
|
693
|
+
years: Number.maybe
|
|
694
|
+
}
|
|
695
|
+
end
|
|
696
|
+
|
|
697
|
+
if code_arguments.any?
|
|
698
|
+
code_wait(
|
|
699
|
+
milliseconds: code_value.code_get(:milliseconds),
|
|
700
|
+
seconds: code_value.code_get(:seconds),
|
|
701
|
+
minutes: code_value.code_get(:minutes),
|
|
702
|
+
hours: code_value.code_get(:hours),
|
|
703
|
+
days: code_value.code_get(:days),
|
|
704
|
+
months: code_value.code_get(:months),
|
|
705
|
+
years: code_value.code_get(:years)
|
|
706
|
+
)
|
|
707
|
+
else
|
|
708
|
+
code_wait
|
|
709
|
+
end
|
|
665
710
|
when "Number"
|
|
666
711
|
sig(args) { Object.repeat }
|
|
667
712
|
if code_arguments.any?
|
|
@@ -688,6 +733,38 @@ class Code
|
|
|
688
733
|
end
|
|
689
734
|
end
|
|
690
735
|
end
|
|
736
|
+
|
|
737
|
+
def code_wait(
|
|
738
|
+
milliseconds: nil,
|
|
739
|
+
seconds: nil,
|
|
740
|
+
minutes: nil,
|
|
741
|
+
hours: nil,
|
|
742
|
+
days: nil,
|
|
743
|
+
months: nil,
|
|
744
|
+
years: nil
|
|
745
|
+
)
|
|
746
|
+
values = {
|
|
747
|
+
milliseconds: milliseconds,
|
|
748
|
+
seconds: seconds,
|
|
749
|
+
minutes: minutes,
|
|
750
|
+
hours: hours,
|
|
751
|
+
days: days,
|
|
752
|
+
months: months,
|
|
753
|
+
years: years
|
|
754
|
+
}
|
|
755
|
+
duration =
|
|
756
|
+
if values.values.all?(&:nil?)
|
|
757
|
+
1
|
|
758
|
+
else
|
|
759
|
+
WAIT_UNIT_SECONDS.sum do |unit, seconds_per_unit|
|
|
760
|
+
value = values.fetch(unit).to_code
|
|
761
|
+
value.nothing? ? 0 : value.raw * seconds_per_unit
|
|
762
|
+
end
|
|
763
|
+
end
|
|
764
|
+
|
|
765
|
+
::Kernel.sleep(duration)
|
|
766
|
+
Nothing.new
|
|
767
|
+
end
|
|
691
768
|
end
|
|
692
769
|
end
|
|
693
770
|
end
|