code-ruby 5.0.4 → 5.0.6

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 +112 -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: 5963b86d5da47531a3cdb1e0dfc740e40d0ce1d0dc4b381404cccdc3e71d42b7
4
+ data.tar.gz: 91f10f5aae107a12869804601768eabef6937e02637dfae037de3cabae698e31
5
5
  SHA512:
6
- metadata.gz: 3b892dc02af2a3989391904ee4a05ee217164cbb2c5afcc04b0f3c59e9991d7daa9eeec44bcfcafe7ab0cf6bd904bd1b6f82fd61fbb00ab83c7adfc32b7c73c4
7
- data.tar.gz: 74b89492158dbd909651f06f9a5d4b466260678651d13775f78e0598a785895454263c5e9e1dbfb4af8fb2de246af2d079e61e39c0c43e983f2e2cca127e4e26
6
+ metadata.gz: a99802efe33c9737f812734bcff47fa42a749cbc6734ad319d3f1d9f9414ebfb93c6d2e832b6c29894bb2cf2ec1488dcd8992b4595e1bacdfb384377e791d365
7
+ data.tar.gz: c2f6e44533b734cb197d3e7cb05312b8c0437907be9b243cea78621aee695243774e006bb9aa2e5cffad666f85992d924f6c479bf64913de64dec72b361de714
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.0.4
1
+ 5.0.6
@@ -90,6 +90,22 @@ class Code
90
90
  "run bin/code 'List.instance_functions.keys'"
91
91
  ]
92
92
  }.freeze
93
+ WAIT_UNIT_SECONDS = {
94
+ millisecond: 0.001,
95
+ milliseconds: 0.001,
96
+ second: 1,
97
+ seconds: 1,
98
+ minute: ::ActiveSupport::Duration::SECONDS_PER_MINUTE,
99
+ minutes: ::ActiveSupport::Duration::SECONDS_PER_MINUTE,
100
+ hour: ::ActiveSupport::Duration::SECONDS_PER_HOUR,
101
+ hours: ::ActiveSupport::Duration::SECONDS_PER_HOUR,
102
+ day: ::ActiveSupport::Duration::SECONDS_PER_DAY,
103
+ days: ::ActiveSupport::Duration::SECONDS_PER_DAY,
104
+ month: ::ActiveSupport::Duration::SECONDS_PER_MONTH,
105
+ months: ::ActiveSupport::Duration::SECONDS_PER_MONTH,
106
+ year: ::ActiveSupport::Duration::SECONDS_PER_YEAR,
107
+ years: ::ActiveSupport::Duration::SECONDS_PER_YEAR
108
+ }.freeze
93
109
  FUNCTIONS = {
94
110
  "Base64" => {
95
111
  name: "Base64",
@@ -362,6 +378,16 @@ class Code
362
378
  "writes values to error with newlines and returns nothing.",
363
379
  examples: ["warn(:hello)", "warn(1, 2)", "warn(\"hello\")"]
364
380
  },
381
+ "wait" => {
382
+ name: "wait",
383
+ description:
384
+ "waits for the combined duration, defaulting to one second, and returns nothing.",
385
+ examples: [
386
+ "wait(second: 0)",
387
+ "wait(minutes: 0, second: 0)",
388
+ "wait(hour: 0, days: 0, month: 0, years: 0, millisecond: 0)"
389
+ ]
390
+ },
365
391
  "read" => {
366
392
  name: "read",
367
393
  description: "reads one line from input.",
@@ -662,6 +688,46 @@ class Code
662
688
  sig(args) { Object.repeat }
663
689
  args.fetch(:error).puts(*code_arguments.raw)
664
690
  Nothing.new
691
+ when "wait"
692
+ sig(args) do
693
+ {
694
+ millisecond: Number.maybe,
695
+ milliseconds: Number.maybe,
696
+ second: Number.maybe,
697
+ seconds: Number.maybe,
698
+ minute: Number.maybe,
699
+ minutes: Number.maybe,
700
+ hour: Number.maybe,
701
+ hours: Number.maybe,
702
+ day: Number.maybe,
703
+ days: Number.maybe,
704
+ month: Number.maybe,
705
+ months: Number.maybe,
706
+ year: Number.maybe,
707
+ years: Number.maybe
708
+ }
709
+ end
710
+
711
+ if code_arguments.any?
712
+ code_wait(
713
+ millisecond: code_value.code_get(:millisecond),
714
+ milliseconds: code_value.code_get(:milliseconds),
715
+ second: code_value.code_get(:second),
716
+ seconds: code_value.code_get(:seconds),
717
+ minute: code_value.code_get(:minute),
718
+ minutes: code_value.code_get(:minutes),
719
+ hour: code_value.code_get(:hour),
720
+ hours: code_value.code_get(:hours),
721
+ day: code_value.code_get(:day),
722
+ days: code_value.code_get(:days),
723
+ month: code_value.code_get(:month),
724
+ months: code_value.code_get(:months),
725
+ year: code_value.code_get(:year),
726
+ years: code_value.code_get(:years)
727
+ )
728
+ else
729
+ code_wait
730
+ end
665
731
  when "Number"
666
732
  sig(args) { Object.repeat }
667
733
  if code_arguments.any?
@@ -688,6 +754,52 @@ class Code
688
754
  end
689
755
  end
690
756
  end
757
+
758
+ def code_wait(
759
+ millisecond: nil,
760
+ milliseconds: nil,
761
+ second: nil,
762
+ seconds: nil,
763
+ minute: nil,
764
+ minutes: nil,
765
+ hour: nil,
766
+ hours: nil,
767
+ day: nil,
768
+ days: nil,
769
+ month: nil,
770
+ months: nil,
771
+ year: nil,
772
+ years: nil
773
+ )
774
+ values = {
775
+ millisecond: millisecond,
776
+ milliseconds: milliseconds,
777
+ second: second,
778
+ seconds: seconds,
779
+ minute: minute,
780
+ minutes: minutes,
781
+ hour: hour,
782
+ hours: hours,
783
+ day: day,
784
+ days: days,
785
+ month: month,
786
+ months: months,
787
+ year: year,
788
+ years: years
789
+ }
790
+ duration =
791
+ if values.values.all?(&:nil?)
792
+ 1
793
+ else
794
+ WAIT_UNIT_SECONDS.sum do |unit, seconds_per_unit|
795
+ value = values.fetch(unit).to_code
796
+ value.nothing? ? 0 : value.raw * seconds_per_unit
797
+ end
798
+ end
799
+
800
+ ::Kernel.sleep(duration)
801
+ Nothing.new
802
+ end
691
803
  end
692
804
  end
693
805
  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.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié