hashlation 1.0.0 → 1.1.1
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/README.md +10 -29
- data/hashlation.gemspec +1 -1
- data/lib/hashlation/version.rb +1 -1
- data/lib/hashlation.rb +6 -6
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 52fc04f602d14cd91c6c7f9041b1fe49700e522b4dee867334d646e2961ba3ec
|
|
4
|
+
data.tar.gz: e018fc8740c10f9cf02f5fab2b4e5c7439df395e7ef0fd18aa362dad2b15667c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ffc0fb90dd2edd7d3188e4b4f080a53f28189a4a3605384db2077878048af9453e62fd702e815a48094c8d091517d24c328a08d909e501d2b09336d571941991
|
|
7
|
+
data.tar.gz: 7c091b00481934e018c8af726dd0a6b1e9d34a981b263667884892da6de0e3bf80ec58349fcbb982e1f98aad87ed9e730bc18edfc4d882de7a11c66b39656e7a
|
data/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Hashlation
|
|
2
2
|
|
|
3
|
+
FAST and VERSATILE hash transformer. Born of the need to more easily read and traverse deeply nested response objects. Faster at 1 to 1 comparisons and more versatile than both OpenStruct and Hashie.
|
|
4
|
+
|
|
3
5
|
## Installation
|
|
4
6
|
|
|
5
7
|
Add this line to your application's Gemfile:
|
|
@@ -19,49 +21,28 @@ Or install it yourself as:
|
|
|
19
21
|
|
|
20
22
|
|
|
21
23
|
|
|
22
|
-
##
|
|
24
|
+
## Usage
|
|
23
25
|
|
|
24
26
|
The returned `obj` includes the method `.keys` to list the keys on the object at every level.
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
### Simple
|
|
29
|
-
|
|
30
|
-
Handles simple string/symbol keys in conversion as well as singleton_methods. Very fast, but cannot handle edge cases in keys.
|
|
31
|
-
|
|
32
|
-
Usage:
|
|
33
|
-
|
|
34
|
-
`obj = Hashlation::Simple.new(hash)`
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
---
|
|
38
|
-
|
|
39
|
-
### Complex
|
|
28
|
+
`obj = Hashlation::Any.new(hash)`
|
|
40
29
|
|
|
41
|
-
Handles
|
|
42
|
-
|
|
43
|
-
Usage:
|
|
44
|
-
|
|
45
|
-
`obj = Hashlation::Complex.new(hash)`
|
|
46
|
-
|
|
47
|
-
---
|
|
48
|
-
|
|
49
|
-
** If `Complex` fails due to inability to read a key, please report in GitHub Issues. Thanks! **
|
|
30
|
+
Handles both simple and complex string/symbol keys in translation. Defines singleton_methods for keys ending in '?'.
|
|
50
31
|
|
|
51
32
|
---
|
|
52
33
|
|
|
53
34
|
## Translated Keys Format:
|
|
54
35
|
|
|
55
|
-
Keys that cannot be set as-is by attr_accessor will be transformed.
|
|
56
|
-
|
|
57
|
-
### Simple:
|
|
36
|
+
Keys that cannot be set as-is by attr_accessor will be transformed. For example:
|
|
58
37
|
|
|
59
38
|
- `'Test-Name' -> obj.test_name`
|
|
60
39
|
|
|
61
|
-
### Complex:
|
|
62
|
-
|
|
63
40
|
- `'11123:12312' -> obj._11123_12312`
|
|
64
41
|
|
|
42
|
+
** If `Any` fails due to inability to read a key, please report in GitHub Issues. Thanks! **
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
65
46
|
## Development
|
|
66
47
|
|
|
67
48
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/hashlation.gemspec
CHANGED
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
|
9
9
|
spec.email = ["56176404+rharris389@users.noreply.github.com"]
|
|
10
10
|
|
|
11
11
|
spec.summary = "Lightweight response parsing"
|
|
12
|
-
spec.description = "Lightweight parser for cleaner navigation of large
|
|
12
|
+
spec.description = "Lightweight parser for cleaner navigation of large and deeply nested hashes."
|
|
13
13
|
spec.homepage = "https://github.com/rharris389/hashlation"
|
|
14
14
|
spec.license = "MIT"
|
|
15
15
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
data/lib/hashlation/version.rb
CHANGED
data/lib/hashlation.rb
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
require_relative "hashlation/version"
|
|
4
4
|
|
|
5
5
|
module Hashlation
|
|
6
|
-
# SHOULD process ANY Hash object return, if object if failing
|
|
7
|
-
#
|
|
6
|
+
# SHOULD process ANY Hash object return, if object if failing it is likely that a key is not getting transformed correctly.
|
|
7
|
+
# Add that character to the transformation string to process correctly.
|
|
8
8
|
class Any
|
|
9
9
|
# Only Assumption is that base level object is a Hash Array or Hash Object
|
|
10
10
|
def initialize(i, key: nil)
|
|
@@ -23,8 +23,8 @@ module Hashlation
|
|
|
23
23
|
array = []
|
|
24
24
|
unless i.empty?
|
|
25
25
|
i.each do |array_item|
|
|
26
|
-
array << case array_item
|
|
27
|
-
when
|
|
26
|
+
array << case array_item
|
|
27
|
+
when Hash || Array
|
|
28
28
|
Any.new(array_item)
|
|
29
29
|
else
|
|
30
30
|
array_item
|
|
@@ -46,7 +46,6 @@ module Hashlation
|
|
|
46
46
|
handle_method(key: key, value: value)
|
|
47
47
|
else
|
|
48
48
|
k_underscore = (key.instance_of? Symbol) ? key : key.underscore
|
|
49
|
-
|
|
50
49
|
case value
|
|
51
50
|
when Hash
|
|
52
51
|
res = Any.new(value, key: k_underscore)
|
|
@@ -72,8 +71,8 @@ module Hashlation
|
|
|
72
71
|
end
|
|
73
72
|
end
|
|
74
73
|
|
|
74
|
+
# Use Begin/Rescue to submit complex keys be sanitized and written to attr_accessor without needlessly checking keys.
|
|
75
75
|
def handle_complex_key(key, value)
|
|
76
|
-
# If this is to be responses may contain improper keys, uncomment and implement for all attr names
|
|
77
76
|
k_special_underscore = key[0,1] =~ /^[0-9].*/ ? "_#{key.tr(':', '_').underscore}" : key.tr(':', '_').underscore
|
|
78
77
|
self.class.attr_accessor(k_special_underscore)
|
|
79
78
|
send("#{k_special_underscore}=", value)
|
|
@@ -87,6 +86,7 @@ module Hashlation
|
|
|
87
86
|
end
|
|
88
87
|
end
|
|
89
88
|
|
|
89
|
+
# Get keys at this object level.
|
|
90
90
|
def keys
|
|
91
91
|
instance_variables
|
|
92
92
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hashlation
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- rharris389
|
|
@@ -10,7 +10,8 @@ bindir: exe
|
|
|
10
10
|
cert_chain: []
|
|
11
11
|
date: 2022-05-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
|
-
description: Lightweight parser for cleaner navigation of large
|
|
13
|
+
description: Lightweight parser for cleaner navigation of large and deeply nested
|
|
14
|
+
hashes.
|
|
14
15
|
email:
|
|
15
16
|
- 56176404+rharris389@users.noreply.github.com
|
|
16
17
|
executables: []
|