Olib 2.0.0.pre.rc.4 → 2.0.0.pre.rc.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67b2a5fcaa0b1e8ea96d2326a9d74093e75f3f67545e63d269cd5e2834946545
4
- data.tar.gz: f1d1e645ef5b63d23afe1f1dd632fdedb4e456b271dad2495a01aa7ce222e914
3
+ metadata.gz: 7f04ae1eaa92abcb12804d1406ef80a11d9bb72c5d6c3a37143b10beef50a4c6
4
+ data.tar.gz: a66cc0f978fa68f09ad657d4a8c9cea2d70d6b2e05475488327382b963f4ebf6
5
5
  SHA512:
6
- metadata.gz: b228aa4fd9ad54c9e8e7b2ff17da544020992e98d76538d786a4103022c78c43a7ce7513b0a3e5bf56e04efd8aaec7743223c0d1b928e63856381c5750d98c75
7
- data.tar.gz: 9f650744fe4431345c990ecc0c7a895211a6f83a6ac8a890c66db73a4c8f4b3cb454c487a7ae4fce2e8af38ce19f209e7bf323e429efccb24120dd395456b0ef
6
+ metadata.gz: 86a62a35112d0cc9f7cb61c04c64298eb8ca815a9abaa57cf22c8c45882bd12922db60d75d0d1ee549c3ddf2235647e8d08b7928ae1620a963869f45d6b8a540
7
+ data.tar.gz: 69522e8c7f8e24e57e6edd622de3ddbbc0dce33213308f7ab33ccf514b7793d4da2e0d592688e92369ca928b673eabfb39cc866fd29a4f11afc2e5591fbce675
@@ -1,4 +1,10 @@
1
1
  module Action
2
+ LOCK = Mutex.new
3
+
4
+ def self.lock()
5
+ LOCK.synchronize { yield }
6
+ end
7
+
2
8
  def self.try_or_fail(seconds: 5, command: nil)
3
9
  fput(command)
4
10
  expiry = Time.now + seconds
@@ -10,8 +10,9 @@ class Loot
10
10
  end
11
11
 
12
12
  def each()
13
- GameObj.loot.to_a.map do |obj| Item.new(obj) end
13
+ GameObj.loot.to_a
14
14
  .reject(&Where[noun: "disk"])
15
+ .map do |obj| Item.new(obj) end
15
16
  .select(&@predicate)
16
17
  .each do |item| yield(item) end
17
18
  end
@@ -0,0 +1,42 @@
1
+ ##
2
+ ## minimal options parser
3
+ ##
4
+ module Opts
5
+ FLAG_PREFIX = "--"
6
+
7
+ def self.parse_command(h, c)
8
+ h[c.to_sym] = true
9
+ end
10
+
11
+ def self.parse_flag(h, f)
12
+ (name, val) = f[2..-1].split("=")
13
+ if val.nil?
14
+ h[name.to_sym] = true
15
+ else
16
+ val = val.split(",")
17
+
18
+ h[name.to_sym] = val.size == 1 ? val.first : val
19
+ end
20
+ end
21
+
22
+ def self.parse(args = Script.current.vars[1..-1])
23
+ OpenStruct.new(**args.to_a.reduce(Hash.new) do |opts, v|
24
+ if v.start_with?(FLAG_PREFIX)
25
+ Opts.parse_flag(opts, v)
26
+ else
27
+ Opts.parse_command(opts, v)
28
+ end
29
+ opts
30
+ end)
31
+ end
32
+
33
+ def self.as_list(key)
34
+ val = to_h.fetch(key.to_sym, [])
35
+ val = [val] if val.is_a?(String)
36
+ return val
37
+ end
38
+
39
+ def self.method_missing(method, *args)
40
+ parse.send(method, *args)
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module Olib
2
- VERSION = "2.0.0-rc.4"
2
+ VERSION = "2.0.0-rc.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Olib
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.rc.4
4
+ version: 2.0.0.pre.rc.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondreian Shamsiel
@@ -62,6 +62,7 @@ files:
62
62
  - lib/Olib/objects/scroll.rb
63
63
  - lib/Olib/objects/uncommon.rb
64
64
  - lib/Olib/objects/wand.rb
65
+ - lib/Olib/opts.rb
65
66
  - lib/Olib/pattern_matching/any.rb
66
67
  - lib/Olib/pattern_matching/err.rb
67
68
  - lib/Olib/pattern_matching/ok.rb