open_hash 0.1.3 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -3
  3. data/Gemfile.lock +1 -1
  4. data/lib/open_hash.rb +34 -5
  5. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7cdfc75952384faa1c6353e1be9980030c08648af5868de5d01a36ff068a99a
4
- data.tar.gz: 2f8302f5d25d65f51dc16aa08aef49b18436d394473c6703c37769fcd6075d21
3
+ metadata.gz: 13454c621c7953de66e52401787727571d0c857afed15a06d305d185bb89c915
4
+ data.tar.gz: e6acbd3d815e4223752a8f7b996e28a883bc4e1827aa7a158c946ad2681ecebd
5
5
  SHA512:
6
- metadata.gz: b750f7935a565236b11d5d93a18c9868c9d58780999e5e1501e561400b75f58bb46b1b8873a849bc626f4eda7873fdfbbf395d8d4811739f9ccc6256388a61fa
7
- data.tar.gz: 47edf215aad380dc77e4f094e222a121e920165b605526e22c47213019a0c4d43320fe84d2cc3ed6424568ba123c7a1c8236f2f9fdab63f5a97572db4a5c6023
6
+ metadata.gz: 3041f5798d8f347716f5302fe632a2bab7536a3890f4df49dd4ef452a338d5478792907ccbca3c9b73bf1aa3df94ab16d5945de8eec662887481846f6666ca45
7
+ data.tar.gz: 17b25b59e6c319e99a45d2a8793beabaa4d55301f83d93c9056b6c37a25de952225400aa747349535a8950c4abd127e1343dcba6d62e356366f26281b6bcb292
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
- ## [Unreleased]
1
+ #Changelog
2
+ ### 0.2.0
3
+ * Add support for using arguments in initializer
2
4
 
3
- ## [0.1.0] - 2023-06-30
5
+ *Reegan Viljoen*
4
6
 
5
- - Initial release
7
+ * Add `.to_open_hash` method to convert hashes into open_hashes
8
+
9
+ *Reegan Viljoen*
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- open_hash (0.1.3)
4
+ open_hash (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/open_hash.rb CHANGED
@@ -1,8 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class OpenHash < Hash
4
+
5
+ def initialize(hash = {})
6
+ hash.each do |key, value|
7
+ self[key] = value
8
+ end
9
+ end
10
+
4
11
  def method_missing(method_name, *args, &block)
5
- if has_key?(method_name)
12
+ if method_name.to_s.end_with?("?")
13
+ has_key?(method_name.to_s.chomp("?").to_sym) || has_key?(method_name.to_s.chomp("?"))
14
+ elsif has_key?(method_name)
6
15
  self[method_name]
7
16
  elsif has_key?(method_name.to_s)
8
17
  self[method_name.to_s]
@@ -14,15 +23,35 @@ class OpenHash < Hash
14
23
  end
15
24
 
16
25
  def methods
17
- setter_keys = keys.map { |key| "#{key}=".to_sym }
18
- super + keys.map(&:to_sym) + setter_keys
26
+ super + setter_methods + getter_methods + predicate_methods
19
27
  end
20
28
 
21
29
  module VERSION
22
30
  MAJOR = 0
23
- MINOR = 1
24
- TINY = 3
31
+ MINOR = 2
32
+ TINY = 1
25
33
 
26
34
  STRING = [MAJOR, MINOR, TINY].compact.join(".")
27
35
  end
36
+
37
+
38
+ private
39
+
40
+ def setter_methods
41
+ keys.map { |key| "#{key}=".to_sym }
42
+ end
43
+
44
+ def getter_methods
45
+ keys.map(&:to_sym)
46
+ end
47
+
48
+ def predicate_methods
49
+ keys.map { |key| "#{key}?".to_sym }
50
+ end
51
+ end
52
+
53
+ class Hash
54
+ def to_open_hash
55
+ OpenHash.new(self)
56
+ end
28
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reegan Viljoen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-30 00:00:00.000000000 Z
11
+ date: 2023-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -55,12 +55,12 @@ files:
55
55
  - lib/open_hash.rb
56
56
  - open_hash.gemspec
57
57
  - sig/open_hash.rbs
58
- homepage:
58
+ homepage:
59
59
  licenses: []
60
60
  metadata:
61
61
  homepage_uri: https://github.com/reeganviljoen/open_hash
62
62
  source_code_uri: https://github.com/reeganviljoen/open_hash
63
- post_install_message:
63
+ post_install_message:
64
64
  rdoc_options: []
65
65
  require_paths:
66
66
  - lib
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  requirements: []
78
78
  rubygems_version: 3.4.1
79
- signing_key:
79
+ signing_key:
80
80
  specification_version: 4
81
81
  summary: Hashes with keys and methods!
82
82
  test_files: []