structverse 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +55 -0
  3. data/lib/structverse.rb +27 -0
  4. metadata +58 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9ed3c7f4a429f0a0f0eda714b92978c8694c476013c56e02d57e866f4cc5e84b
4
+ data.tar.gz: 9c9462dae83d350f344379c119528a8007a6eeb15b0eab6ef1e514c39cd379f4
5
+ SHA512:
6
+ metadata.gz: cb92041d5f8f4949727e1eb82dded818b1c16f0588536b1270f20f354bdc84efe2e8a49d0227c86d469ae76353d86dbca57d6e23dc2cf7a983f5f996a71741ac
7
+ data.tar.gz: c552f236b19b3d2e8e1383216c762728699065703e68ed9b174b88634fdef2e3589357695efbd4edc72743a65045f6b27ec4b3cc77a37bf0cf9870844e239218
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Structverse
2
+
3
+ Structverse provides a simple way to walk through tyhe structure of a hash or
4
+ array. Call `Structverse.walk`, passing in the hash or array. The `walk` method
5
+ will return each hash and array in the structure. Only hashes as arrays are
6
+ returned.
7
+
8
+ ```ruby
9
+ #!/usr/bin/ruby -w
10
+ require 'structverse'
11
+
12
+ hsh = {
13
+ "Puck": true,
14
+
15
+ "Oberon": {
16
+ "Titania": [
17
+ "Peaseblossom",
18
+ "Mustardseed",
19
+ { "Mote": true },
20
+ [ "Bottom", "Flute" ]
21
+ ]
22
+ }
23
+ }
24
+
25
+ Structverse.walk(hsh) do |struct|
26
+ puts struct.class
27
+ end
28
+
29
+ # => Hash
30
+ # => Hash
31
+ # => Array
32
+ # => Hash
33
+ # => Array
34
+ ```
35
+
36
+ ## Installation
37
+
38
+ The usual:
39
+
40
+ ```bash
41
+ sudo gem install structverse
42
+ ```
43
+ Or however you like to installgems. It's just a single file.
44
+
45
+
46
+ ## Author
47
+
48
+ Mike O'Sullivan
49
+ mike@idocs.com
50
+
51
+ ## History
52
+
53
+ | version | date | notes |
54
+ |---------|---------------|-------------------------------|
55
+ | 1.0 | June 22, 2023 | Initial upload. |
@@ -0,0 +1,27 @@
1
+ module Structverse
2
+ VERSION = '1.0'
3
+
4
+ # walk
5
+
6
+ # Walks an array or hash structure.
7
+ # Structverse.walk(hsh) do |struct|
8
+ # puts struct.class
9
+ # end
10
+
11
+ def self.walk(struct, &block)
12
+ if struct.is_a?(Hash) or struct.is_a?(Array)
13
+ yield struct
14
+
15
+ if struct.is_a?(Hash)
16
+ struct.values.each do |v|
17
+ walk v, &block
18
+ end
19
+
20
+ elsif struct.is_a?(Array)
21
+ struct.each do |v|
22
+ walk v, &block
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: structverse
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Mike O'Sullivan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-06-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description: Utility for traversing hashes and arrays.
28
+ email: mike@idocs.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.md
34
+ - lib/structverse.rb
35
+ homepage: https://github.com/mikosullivan/structverse
36
+ licenses:
37
+ - MIT
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.3.5
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Structverse
58
+ test_files: []