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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/code/object/global.rb +77 -0
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21c1d020597fb58110205295051761fb8803f227c4a16110525740cf68d52830
4
- data.tar.gz: 7b3ee5d96b0de1c5c5c9a5f462989beef1718b41d8eeacc62082f13a8616ce9b
3
+ metadata.gz: 2a357d174303776eaab433e14c7a885a4490abb35bc7c64eeffa8fb1ca61e990
4
+ data.tar.gz: 1d024540aaabdffe957c6a565f94e52d8bdfbfa57635bb4d9062eb8873534906
5
5
  SHA512:
6
- metadata.gz: 3b892dc02af2a3989391904ee4a05ee217164cbb2c5afcc04b0f3c59e9991d7daa9eeec44bcfcafe7ab0cf6bd904bd1b6f82fd61fbb00ab83c7adfc32b7c73c4
7
- data.tar.gz: 74b89492158dbd909651f06f9a5d4b466260678651d13775f78e0598a785895454263c5e9e1dbfb4af8fb2de246af2d079e61e39c0c43e983f2e2cca127e4e26
6
+ metadata.gz: 8e73ccd87a9fa3f1994b0b11bd9db954950671458fb77d88db349bebb775bc3e3b39eeb9fce5b87872cadbeb18454838f55200da9b3e938777952b49e45b63ed
7
+ data.tar.gz: 9661ddad724eeb12de32f4af27b356591d8213d7f39db172e4a6628ae5b762122601ad4e876d00cf7bac8c4e55dbb8c9414239ea8213fe1a5924d8922f1e2bad
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.0.4
1
+ 5.0.5
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.4
4
+ version: 5.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié