hash_wia 0.7.6 → 0.7.7
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/hash_wia/class.rb +49 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afe16ea4e4d8f3fdb8aeb049db4b22841a5b3ac195dd8fe017d6c48dca229de6
|
4
|
+
data.tar.gz: 46633e2df0827031dbafdbb8ad335975329d2c876c1209b21a2ec98c15ec10d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6563528dd2841ce621639b3c2d96b29d8299d9ec335f99d83b647d91e421c5192d9ffd3eaa0748c217e34219ac6a57844f284d345fd9d4e019341f0abf49e849
|
7
|
+
data.tar.gz: 4517ab23a0a7d2246483f16037dfe949a6264a73ce8e82ec3136651083402bfe8dfec468c72bc7b4cf782cba53e5fe4a4fbecacd1b8970b3b3654997f8c302f2
|
data/.version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.7
|
data/lib/hash_wia/class.rb
CHANGED
@@ -1,3 +1,52 @@
|
|
1
1
|
class HashWia < Hash
|
2
2
|
include HashWiaModule
|
3
3
|
end
|
4
|
+
|
5
|
+
class HashWia
|
6
|
+
class NamedOptions
|
7
|
+
def initialize hash
|
8
|
+
@hash = hash
|
9
|
+
end
|
10
|
+
|
11
|
+
def set code, constant, name = nil
|
12
|
+
unless name
|
13
|
+
name = constant.keys.first
|
14
|
+
constant = constant.values.first
|
15
|
+
end
|
16
|
+
|
17
|
+
@hash[code.to_s] = name.to_s
|
18
|
+
@hash[constant.to_s] = code.to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def method_missing code, *args
|
22
|
+
self.set code, *args
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# to create Task::STATUS and Task.status
|
28
|
+
# HashWia self, :status do |opt|
|
29
|
+
#
|
30
|
+
# or just to get a hash
|
31
|
+
# HashWia do |opt|
|
32
|
+
# opt.DONE d: 'Done'
|
33
|
+
# # or
|
34
|
+
# opt.DONE :d, 'Done'
|
35
|
+
# end
|
36
|
+
def HashWia klass = nil, name = nil
|
37
|
+
if block_given?
|
38
|
+
hash = HashWia.new
|
39
|
+
|
40
|
+
if name
|
41
|
+
constant = name.to_s.upcase
|
42
|
+
klass.const_set constant, hash
|
43
|
+
klass.define_singleton_method(name) { klass.const_get(constant) }
|
44
|
+
end
|
45
|
+
|
46
|
+
named_opts = HashWia::NamedOptions.new hash
|
47
|
+
yield named_opts
|
48
|
+
hash
|
49
|
+
else
|
50
|
+
raise ArgumentError, 'Block not provided'
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_wia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dino Reic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Gem provides simple access to common Ruby hash types bundled in one simple
|
14
14
|
class
|