code-ruby 5.0.3 → 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 +87 -0
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c19839210f13057cf11e83849e691bfa59fc63720891af5feef70afebe4d15a
4
- data.tar.gz: 9f3376a950170b7208b062a3f29a1642da5e80169dbed83c3bcab099ebc3ad7c
3
+ metadata.gz: 2a357d174303776eaab433e14c7a885a4490abb35bc7c64eeffa8fb1ca61e990
4
+ data.tar.gz: 1d024540aaabdffe957c6a565f94e52d8bdfbfa57635bb4d9062eb8873534906
5
5
  SHA512:
6
- metadata.gz: ed16c6eddc5904d2fb8b95074f5ae1c2a445f1e1602efab82ac536348749ec7b3f6cfa907d88997b0b6ec9d7c72f886ad441734656f2d1edd7aaf3b4d64dbfc7
7
- data.tar.gz: b214393a66a7d700b7be24b3fab4b8555be1e870f45dcf9b0b034c2bff67b62e4c5cae068f0539e490d4bfc37e32ddd94742653ddcb2bc88bcf4fcfd302480ed
6
+ metadata.gz: 8e73ccd87a9fa3f1994b0b11bd9db954950671458fb77d88db349bebb775bc3e3b39eeb9fce5b87872cadbeb18454838f55200da9b3e938777952b49e45b63ed
7
+ data.tar.gz: 9661ddad724eeb12de32f4af27b356591d8213d7f39db172e4a6628ae5b762122601ad4e876d00cf7bac8c4e55dbb8c9414239ea8213fe1a5924d8922f1e2bad
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.0.3
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",
@@ -356,6 +365,22 @@ class Code
356
365
  "writes values to output with newlines and returns nothing.",
357
366
  examples: ["puts(:hello)", "puts(1, 2)", "puts(\"hello\")"]
358
367
  },
368
+ "warn" => {
369
+ name: "warn",
370
+ description:
371
+ "writes values to error with newlines and returns nothing.",
372
+ examples: ["warn(:hello)", "warn(1, 2)", "warn(\"hello\")"]
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
+ },
359
384
  "read" => {
360
385
  name: "read",
361
386
  description: "reads one line from input.",
@@ -652,6 +677,36 @@ class Code
652
677
  sig(args) { Object.repeat }
653
678
  output.puts(*code_arguments.raw)
654
679
  Nothing.new
680
+ when "warn"
681
+ sig(args) { Object.repeat }
682
+ args.fetch(:error).puts(*code_arguments.raw)
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
655
710
  when "Number"
656
711
  sig(args) { Object.repeat }
657
712
  if code_arguments.any?
@@ -678,6 +733,38 @@ class Code
678
733
  end
679
734
  end
680
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
681
768
  end
682
769
  end
683
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.3
4
+ version: 5.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié