{"id":15605696,"url":"https://github.com/gangelo/mad_flatter","last_synced_at":"2025-06-25T16:06:27.729Z","repository":{"id":57749944,"uuid":"525071161","full_name":"gangelo/mad_flatter","owner":"gangelo","description":"mad_flatter is a Ruby gem that takes a Ruby Hash and flattens the Hash keys to create a new Hash with unique Hash keys; that is, embedded Hashes use their respective keys as namespaces to create unique keys across the entire Hash. A `:namespace` option may be applied to append to all Hash keys, to ensure that all Hash keys are unique across multiple Hashes with the same structure.","archived":false,"fork":false,"pushed_at":"2024-11-18T23:43:29.000Z","size":49,"stargazers_count":2,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T08:21:17.751Z","etag":null,"topics":["flatten","flattened-hash","gem","hash","hashing","hashing-library","ruby-gem","ruby-gems","ruby-hash","ruby-hash-methods","rubygem","rubygems"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gangelo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-15T17:07:39.000Z","updated_at":"2024-08-09T23:42:59.000Z","dependencies_parsed_at":"2024-04-23T00:51:37.806Z","dependency_job_id":null,"html_url":"https://github.com/gangelo/mad_flatter","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"aca1ec10fa3ba3e6637d1be40643143449bb786a"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gangelo%2Fmad_flatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gangelo%2Fmad_flatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gangelo%2Fmad_flatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gangelo%2Fmad_flatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gangelo","download_url":"https://codeload.github.com/gangelo/mad_flatter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252846105,"owners_count":21813378,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flatten","flattened-hash","gem","hash","hashing","hashing-library","ruby-gem","ruby-gems","ruby-hash","ruby-hash-methods","rubygem","rubygems"],"created_at":"2024-10-03T04:11:35.626Z","updated_at":"2025-05-07T08:44:05.778Z","avatar_url":"https://github.com/gangelo.png","language":"Ruby","readme":"# MadFlatter\n\n[![GitHub version](http://badge.fury.io/gh/gangelo%2Fmad_flatter.svg?refresh=4)](https://badge.fury.io/gh/gangelo%2Fmad_flatter)\n\n[![Gem Version](https://badge.fury.io/rb/mad_flatter.svg?refresh=4)](https://badge.fury.io/rb/mad_flatter)\n\n[![](http://ruby-gem-downloads-badge.herokuapp.com/mad_flatter?type=total)](http://www.rubydoc.info/gems/mad_flatter/)\n[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/mad_flatter/)\n\n[![Report Issues](https://img.shields.io/badge/report-issues-red.svg)](https://github.com/gangelo/mad_flatter/issues)\n\n[![License](http://img.shields.io/badge/license-MIT-yellowgreen.svg)](#license)\n\nmad_flatter is a Ruby gem that takes a Ruby `Hash` and flattens the Hash keys to create a new Hash with unique Hash keys; that is, embedded Hashes use their\nrespective keys as namespaces to create unique keys across the entire Hash.\nFor example:\n\n```ruby\nuser0 = {\n  name: 'john',\n  wife: { name: 'mary' },\n  children: {\n    child0: 'sam',\n    child1: 'martha'\n  }\n}\n\nresult0 = MadFlatter::Service.new.execute(hash: user0)\n#=\u003e\n{\n  :name=\u003e\"john\",\n  :wife_name=\u003e\"mary\",\n  :children_child0=\u003e\"sam\",\n  :children_child1=\u003e\"martha\"\n}\n```\n\nThe `:namespace` option may be used to append to all Hash keys, to ensure that all Hash keys are unique across multiple Hashes with the same structure. For example:\n\n```ruby\n# Continuing from the above example...\nuser1 = {\n  name: 'james',\n  wife: { name: 'molly' },\n  children: {\n    child0: 'steve',\n    child1: 'maybell'\n  }\n}\n\noptions = { namespace: :ns1 }\nresult1 = MadFlatter::Service.new.execute(hash: user1, options: options)\n#=\u003e\n{\n  :ns1_name=\u003e\"james\",\n  :ns1_wife_name=\u003e\"molly\",\n  :ns1_children_child0=\u003e\"steve\",\n  :ns1_children_child1=\u003e\"maybell\"\n}\n\nresult0.merge(result1)\n#=\u003e\n{\n  :name=\u003e\"john\",\n  :wife_name=\u003e\"mary\",\n  :children_child0=\u003e\"sam\",\n  :children_child1=\u003e\"martha\",\n  :ns1_name=\u003e\"james\",\n  :ns1_wife_name=\u003e\"molly\",\n  :ns1_children_child0=\u003e\"steve\",\n  :ns1_children_child1=\u003e\"maybell\"\n}\n```\n\nThe metadata can optionally be returned by setting the `:metadata` option\nto true. This option is `false` by default. For example:\n\n```ruby\nbest_cake = {\n  name: 'black forest',\n  options: {\n    cherries: false\n  }\n}\n\noptions = { namespace: :best_cake, metadata: true }\nresult = MadFlatter::Service.new(options: options).execute(hash: best_cake)\n#=\u003e\n{\n  :best_cake_name=\u003e\n    {\n      :value=\u003e\"black forest\",\n      :metadata=\u003e {\n        :key=\u003e:name,\n        :dig=\u003e[]\n      }\n    },\n  :best_cake_options_cherries=\u003e {\n    :value=\u003efalse,\n    :metadata=\u003e {\n      :key=\u003e:cherries,\n      :dig=\u003e[:options]\n    }\n  }\n}\n\nresult.each_pair do |key, value|\n  original_key = value[:metadata][:key]\n  original_value = best_cake.dig(*value[:metadata][:dig], original_key)\n  puts 'Original Hash key/value:'\n  puts \"\\t#{original_key} =\u003e \\\"#{original_value}\\\"\"\n  puts 'New Hash key/value:'\n  puts \"\\t#{key} =\u003e \\\"#{value[:value]}\\\"\"\n  puts\nend\n```\n\nPrints:\n\n```\nOriginal Hash key/value:\n\tname =\u003e \"black forest\"\nNew Hash key/value:\n\tbest_cake_name =\u003e \"black forest\"\n\nOriginal Hash key/value:\n\tcherries =\u003e \"false\"\nNew Hash key/value:\n\tbest_cake_options_cherries =\u003e \"false\"\n```\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'mad_flatter'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install mad_flatter\n\n## Development\n\nAfter 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.\n\nTo 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).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mad_flatter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/mad_flatter/blob/main/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the MadFlatter project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/mad_flatter/blob/main/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgangelo%2Fmad_flatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgangelo%2Fmad_flatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgangelo%2Fmad_flatter/lists"}