hashlation 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 844322f953a82a82dba511528598cfd9f7cd16407a5ed8e3a5d8d38f0ece3a7b
4
+ data.tar.gz: f7037b05c2682ac281a9597a95de8ca8fe3c9064e61151992a9ad511025f0c39
5
+ SHA512:
6
+ metadata.gz: 46501563a71f56b65567d4cc74e8c07a51428c080114bf6ed51d3a947110a024eca3995041056097a8b1d852418c0134dff5e56fb271478c81ca737e6d8c33ba
7
+ data.tar.gz: e7069b715a4167e6ff4021e260b6324c6e4414c8483045bd8828d3409dee963dc38189bc3085703e980bfc86cedfa42ebb7684987ea09e6c8e00cb99882a3f36
data/.DS_Store ADDED
Binary file
data/.github/.DS_Store ADDED
Binary file
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 2.7.1
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.15
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.idea/.DS_Store ADDED
Binary file
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Datasource local storage ignored files
5
+ /dataSources/
6
+ /dataSources.local.xml
7
+ # Editor-based HTTP Client requests
8
+ /httpRequests/
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ </module>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ </module>
@@ -0,0 +1,6 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="false" />
5
+ </profile>
6
+ </component>
data/.idea/misc.xml ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="rbenv: 2.7.0" project-jdk-type="RUBY_SDK" />
4
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/hashlation.iml" filepath="$PROJECT_DIR$/.idea/hashlation.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-05-16
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in hashlation.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hashlation (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.5.0)
10
+ rake (13.0.6)
11
+ rspec (3.11.0)
12
+ rspec-core (~> 3.11.0)
13
+ rspec-expectations (~> 3.11.0)
14
+ rspec-mocks (~> 3.11.0)
15
+ rspec-core (3.11.0)
16
+ rspec-support (~> 3.11.0)
17
+ rspec-expectations (3.11.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.11.0)
20
+ rspec-mocks (3.11.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.11.0)
23
+ rspec-support (3.11.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ hashlation!
30
+ rake (~> 13.0)
31
+ rspec (~> 3.0)
32
+
33
+ BUNDLED WITH
34
+ 2.1.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 rharris389
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Hashlation
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'hashlation'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hashlation
18
+
19
+ ## Usage
20
+
21
+ Hashlation::Simple -> Hashlation::Simple.new(hash)
22
+
23
+ Handles simple string/symbol keys in conversion as well as singleton_methods. Much faster, but cannot hanlde edge cases in response.
24
+
25
+ Hashlation::Complex -> Hashlation::Complex.new(hash)
26
+
27
+ Handles MOST key types in conversion. If you know that your keys will contain leading Integer characters, or ':'.
28
+
29
+ **If ::Complex fails due to inability to read key, please report an Issue.**
30
+
31
+ ## Development
32
+
33
+ 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.
34
+
35
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rharris389/hashlation.
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "hashlation"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/hashlation/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "hashlation"
7
+ spec.version = Hashlation::VERSION
8
+ spec.authors = ["rharris389"]
9
+ spec.email = ["56176404+rharris389@users.noreply.github.com"]
10
+
11
+ spec.summary = "Simple/Lightweight hash parsing gem. "
12
+ spec.description = "View keys at every nesting level, "
13
+ spec.homepage = "https://github.com/rharris389/hashlation"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
16
+
17
+ spec.metadata["allowed_push_host"] = 'https://rubygems.org'
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/rharris389/hashlation"
21
+ spec.metadata["changelog_uri"] = "https://github.com/rharris389/hashlation/changelog.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "example-gem", "~> 1.0"
34
+
35
+ # For more information and examples about making a new gem, checkout our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
37
+ end
@@ -0,0 +1,78 @@
1
+ module Hashlation
2
+ # ---------------------------------------COMPLEX PARSER-----------------------------------------
3
+ # SHOULD process ANY Hash object return, if object if failing, it is likely that a key is not getting transformed
4
+ # correctly, add that character to the transformation string to process correctly.
5
+ class Complex
6
+ # Only Assumption is that base level object is a Hash Array or Hash Object
7
+ def initialize(i, key: nil)
8
+ case i
9
+ when Array
10
+ process_array(i, key: key)
11
+ when Hash
12
+ process_hash(i)
13
+ else
14
+ puts 'Base object must be Hash Object or Array'
15
+ end
16
+ end
17
+
18
+ def process_array(i, key: nil)
19
+ attr_key = key ? sanatize_key(key) : 'array'
20
+ array = []
21
+ unless i.empty?
22
+ i.each do |array_item|
23
+ array << case array_item.class.to_s.to_sym
24
+ when :Hash || :Array
25
+ Complex.new(array_item)
26
+ else
27
+ array_item
28
+ end
29
+ end
30
+ end
31
+ self.class.attr_accessor(attr_key)
32
+ send("#{attr_key}=", array)
33
+ instance_variable_set("@#{attr_key}", array)
34
+ end
35
+
36
+ def process_hash(i)
37
+ i.each do |key, value|
38
+ if key[-1, 1] == '?'
39
+ handle_method(key: key, value: value)
40
+ else
41
+ k_underscore = (key.instance_of? Symbol) ? key : sanatize_key(key)
42
+ case value
43
+ when Hash
44
+ res = Complex.new(value, key: k_underscore)
45
+ self.class.attr_accessor
46
+ self.class.attr_accessor(k_underscore)
47
+ send("#{k_underscore}=", res)
48
+ instance_variable_set("@#{k_underscore}", res)
49
+ when Array
50
+ process_array(value, key: k_underscore)
51
+ else
52
+ self.class.attr_accessor(k_underscore)
53
+ send("#{k_underscore}=", value)
54
+ instance_variable_set("@#{k_underscore}", value)
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+
61
+ def sanatize_key(key)
62
+ # If this is to be responses may contain improper keys, uncomment and implement for all attr names
63
+ # the PrimeTrust API responses only need to be underscored as they do not contain leading integers or dis-allowed characters
64
+ key[0,1] =~ /^[0-9].*/ ? "_#{key.tr(':', '_').underscore}" : key.tr(':', '_').underscore
65
+ end
66
+
67
+ # Allows us to handle methods ending with '?' as Singleton Methods
68
+ def handle_method(key:, value:)
69
+ define_singleton_method(key) do
70
+ return value
71
+ end
72
+ end
73
+
74
+ def keys
75
+ instance_variables
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,76 @@
1
+ module Hashlation
2
+ # ---------------------------------------SIMPLE PARSER-----------------------------------------
3
+ # SHOULD process MOST common hash keys quickly. Will fail on Leading integers on keys and inclusion of ':' characters
4
+ class Simple
5
+ # Only Assumption is that base level object is a Hash Array or Hash Object
6
+ def initialize(i, key: nil)
7
+ case i
8
+ when Array
9
+ process_array(i, key: key)
10
+ when Hash
11
+ process_hash(i)
12
+ else
13
+ puts 'Base object must be Hash Object or Array'
14
+ end
15
+ end
16
+
17
+ def process_array(i, key: nil)
18
+ attr_key = key ? sanatize_key(key) : 'array'
19
+ array = []
20
+ unless i.empty?
21
+ i.each do |array_item|
22
+ array << case array_item.class.to_s.to_sym
23
+ when :Hash || :Array
24
+ Simple.new(array_item)
25
+ else
26
+ array_item
27
+ end
28
+ end
29
+ end
30
+ self.class.attr_accessor(attr_key)
31
+ send("#{attr_key}=", array)
32
+ instance_variable_set("@#{attr_key}", array)
33
+ end
34
+
35
+ def process_hash(i)
36
+ i.each do |key, value|
37
+ if key[-1, 1] == '?'
38
+ handle_method(key: key, value: value)
39
+ else
40
+ k_underscore = (key.instance_of? Symbol) ? key : sanatize_key(key)
41
+ case value
42
+ when Hash
43
+ res = Simple.new(value, key: k_underscore)
44
+ self.class.attr_accessor
45
+ self.class.attr_accessor(k_underscore)
46
+ send("#{k_underscore}=", res)
47
+ instance_variable_set("@#{k_underscore}", res)
48
+ when Array
49
+ process_array(value, key: k_underscore)
50
+ else
51
+ self.class.attr_accessor(k_underscore)
52
+ send("#{k_underscore}=", value)
53
+ instance_variable_set("@#{k_underscore}", value)
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ def sanatize_key(key)
60
+ # If this is to be responses may contain improper keys, uncomment and implement for all attr names
61
+ # the PrimeTrust API responses only need to be underscored as they do not contain leading integers or dis-allowed characters
62
+ key.underscore
63
+ end
64
+
65
+ # Allows us to handle methods ending with '?' as Singleton Methods
66
+ def handle_method(key:, value:)
67
+ define_singleton_method(key) do
68
+ return value
69
+ end
70
+ end
71
+
72
+ def keys
73
+ instance_variables
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hashlation
4
+ VERSION = "0.1.0"
5
+ end
data/lib/hashlation.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "hashlation/version"
4
+ require_relative "hashlation/complex"
5
+ require_relative "hashlation/simple"
6
+
7
+ module Hashlation
8
+ class Error < StandardError; end
9
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hashlation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - rharris389
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-05-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'View keys at every nesting level, '
14
+ email:
15
+ - 56176404+rharris389@users.noreply.github.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".DS_Store"
21
+ - ".github/.DS_Store"
22
+ - ".github/workflows/main.yml"
23
+ - ".gitignore"
24
+ - ".idea/.DS_Store"
25
+ - ".idea/.gitignore"
26
+ - ".idea/classify.iml"
27
+ - ".idea/hashlation.iml"
28
+ - ".idea/inspectionProfiles/Project_Default.xml"
29
+ - ".idea/misc.xml"
30
+ - ".idea/modules.xml"
31
+ - ".idea/vcs.xml"
32
+ - ".rspec"
33
+ - CHANGELOG.md
34
+ - Gemfile
35
+ - Gemfile.lock
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - bin/console
40
+ - bin/setup
41
+ - hashlation.gemspec
42
+ - lib/hashlation.rb
43
+ - lib/hashlation/complex.rb
44
+ - lib/hashlation/simple.rb
45
+ - lib/hashlation/version.rb
46
+ homepage: https://github.com/rharris389/hashlation
47
+ licenses:
48
+ - MIT
49
+ metadata:
50
+ allowed_push_host: https://rubygems.org
51
+ homepage_uri: https://github.com/rharris389/hashlation
52
+ source_code_uri: https://github.com/rharris389/hashlation
53
+ changelog_uri: https://github.com/rharris389/hashlation/changelog.md
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.4.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.1.2
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Simple/Lightweight hash parsing gem.
73
+ test_files: []