{"id":13747500,"url":"https://github.com/mdeering/attribute_normalizer","last_synced_at":"2025-10-08T19:12:57.851Z","repository":{"id":601478,"uuid":"237461","full_name":"mdeering/attribute_normalizer","owner":"mdeering","description":"Adds the ability to normalize attributes cleanly with code blocks and predefined normalizers","archived":false,"fork":false,"pushed_at":"2023-12-13T05:44:30.000Z","size":122,"stargazers_count":475,"open_issues_count":19,"forks_count":52,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-09-20T03:44:53.660Z","etag":null,"topics":["activerecord","normalization","rails","ruby"],"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/mdeering.png","metadata":{"files":{"readme":"README.textile","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"ROADMAP.textile","authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2009-06-27T04:39:28.000Z","updated_at":"2025-02-14T15:49:18.000Z","dependencies_parsed_at":"2024-06-18T13:51:04.381Z","dependency_job_id":"0c82d884-7fb8-47c9-8f84-7a87111498d7","html_url":"https://github.com/mdeering/attribute_normalizer","commit_stats":{"total_commits":112,"total_committers":25,"mean_commits":4.48,"dds":0.4821428571428571,"last_synced_commit":"3f21e42024f30ffeabc65cd572570563cff74dd7"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/mdeering/attribute_normalizer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdeering%2Fattribute_normalizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdeering%2Fattribute_normalizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdeering%2Fattribute_normalizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdeering%2Fattribute_normalizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mdeering","download_url":"https://codeload.github.com/mdeering/attribute_normalizer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdeering%2Fattribute_normalizer/sbom","scorecard":{"id":632940,"data":{"date":"2025-08-11","repo":{"name":"github.com/mdeering/attribute_normalizer","commit":"3f21e42024f30ffeabc65cd572570563cff74dd7"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":3,"reason":"Found 9/29 approved changesets -- score normalized to 3","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: MIT-LICENSE:0","Info: FSF or OSI recognized license: MIT License: MIT-LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 10 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-21T08:24:06.970Z","repository_id":601478,"created_at":"2025-08-21T08:24:06.971Z","updated_at":"2025-08-21T08:24:06.971Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278775390,"owners_count":26043813,"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","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["activerecord","normalization","rails","ruby"],"created_at":"2024-08-03T06:01:31.474Z","updated_at":"2025-10-08T19:12:57.807Z","avatar_url":"https://github.com/mdeering.png","language":"Ruby","readme":"h1. Attribute Normalizer\n\n!https://secure.travis-ci.org/mdeering/attribute_normalizer.png?branch=master(Build Status)!:http://travis-ci.org/mdeering/attribute_normalizer\n\np. A little normalization goes a long way in helping maintain data integrity.\n\nh2. Change History\n* 1.1.0\n** Allow the use of default normalizers before and after the evaluation of a given block\n\n* 1.0.0\n** -DSL Changes-\n** Default attributes to normalize\n** mongid support\n\n* 0.3.0\n** Normalizer Chaining\n** Built-in common normalizers\n** Ability to change the default attribute normalization.\n\n* 0.2.1\n** ActiveModel Support Built-in\n** Fix for :with option getting dropped when normalizing several attributes\n\n* 0.2.0\n** Removed the normalization on reads.\n** Added out of the box support for CassandraObjects\n** Included RSpec matcher _normalizer_attribute_\n** Added the ability to define global normalizers\n** *Strings no longer get 'strip' called on them before getting passed on to your defined normalization blocks*\n\nh2. Supported ORMs\n\n* _Active Model_\n* Active Record\n* CassandraObjects\n\np. _I will gladly take pull requests to automatically load Attribute Normalizer into your ORM of choice if requested.  To test it out on your ORM just include the AttributeNormalizer module after requiring it._\n\n\u003cpre\u003e\u003ccode\u003e# your_initializer.rb\nrequire 'attribute_normalizer'\nYourORM::Base.send :include, AttributeNormalizer\u003c/code\u003e\u003c/pre\u003e\n\nh2. Install\n\n\u003cpre\u003e\u003ccode\u003esudo gem install attribute_normalizer\u003c/code\u003e\u003c/pre\u003e\n\np. Then just required it.  Rails usages is as follows.\n\nh3. Rails 2\n\n\u003cpre\u003e\u003ccode\u003e# config/environment.rb\nconfig.gem 'attribute_normalizer'\u003c/code\u003e\u003c/pre\u003e\n\nh3. Rails 3\n\n\u003cpre\u003e\u003ccode\u003e# Gemfile\ngem 'attribute_normalizer'\u003c/code\u003e\u003c/pre\u003e\n\np. It also still works as a traditional Rails plugin.\n\n\u003cpre\u003e\u003ccode\u003e./script/plugin install git://github.com/mdeering/attribute_normalizer.git\u003c/code\u003e\u003c/pre\u003e\n\nh2. Usage\n\np. Lets create a quick test/spec for what we want to accomplish as far as normalization using the built in RSpec matcher.\n\n\u003cpre\u003e\u003ccode\u003e# spec/models/book_spec.rb\ndescribe Book do\n  it { should normalize_attribute(:author) }\n  it { should normalize_attribute(:price).from('$3,450.98').to(3450.98) }\n  it { should normalize_attribute(:summary).from('   Here is my summary that is a little to long   ').to('Here is m...') }\n  it { should normalize_attribute(:title).from(' pick up chicks with magic tricks  ').to('Pick Up Chicks With Magic Tricks') }\n  it { should normalize_attribute(:slug).from(' Social Life at the Edge of Chaos    ').to('social-life-at-the-edge-of-chaos') }\n  it { should normalize_attribute(:limited_slug).from(' Social Life at the Edge of Chaos    ').to('social-life') }\nend\u003c/code\u003e\u003c/pre\u003e\n\np. The following normalizers are already included with the +0.3 version of the gem.\n\n* _:blank_ Will return _nil_ on empty strings\n* _:phone_ Will strip out all non-digit characters and return nil on empty strings\n* _:strip_ Will strip leading and trailing whitespace.\n* _:squish_ Will strip leading and trailing whitespace and convert any consecutive spaces to one space each\n\np. And lets predefine some normalizers that we may use in other classes/models or that we don't want to clutter up our class/model's readability with.\n\n\u003cpre\u003e\u003ccode\u003e# config/initializers/attribute_normalizer.rb\nAttributeNormalizer.configure do |config|\n\n  config.normalizers[:currency] = lambda do |value, options|\n    value.is_a?(String) ? value.gsub(/[^0-9\\.]+/, '') : value\n  end\n\n  config.normalizers[:truncate] = lambda do |text, options|\n    if text.is_a?(String)\n      options.reverse_merge!(:length =\u003e 30, :omission =\u003e \"...\")\n      l = options[:length] - options[:omission].mb_chars.length\n      chars = text.mb_chars\n      (chars.length \u003e options[:length] ? chars[0...l] + options[:omission] : text).to_s\n    else\n      text\n    end\n  end\n\n  # The default normalizers if no :with option or block is given is to apply the :strip and :blank normalizers (in that order).\n  # You can change this if you would like as follows:\n  # config.default_normalizers = :strip, :blank\n\nend\n\u003c/code\u003e\u003c/pre\u003e\n\nThe _normalize_attributes_ method is eager loaded into your ORM.  _normalize_attribute_ is aliased to _normalize_attributes_ and both can take in a single attribute or an array of attributes.\n\n\u003cpre\u003e\u003ccode\u003eclass Book \u003c ActiveRecord::Base\n\n  # By default it will strip leading and trailing whitespace\n  # and set to nil if blank.\n  normalize_attributes :author, :publisher\n\n  # Using one of our predefined normalizers.\n  normalize_attribute  :price, :with =\u003e :currency\n\n  # Using more then one of our predefined normalizers including one with options\n  normalize_attribute :summary, :with =\u003e [ :strip, { :truncate =\u003e { :length =\u003e 12 } } ]\n\n  # You can also define your normalization block inline.\n  normalize_attribute :title do |value|\n    value.is_a?(String) ? value.titleize.strip : value\n  end\n\n  # Or use a combination of normalizers plus an inline block.\n  # the normalizers in the :with option will each be evalulated\n  # in order and the result will be given to the block.\n  # You could also use option :before in place of :with\n  normalize_attribute :slug, :with =\u003e [ :strip, :blank ] do |value|\n    value.present? \u0026\u0026 value.is_a?(String) ? value.downcase.gsub(/\\s+/, '-') : value\n  end\n\n  # Use builtin normalizers before and after the evaluation of your inline\n  # block\n  normalize_attribute :limited_slug, :before =\u003e [ :strip, :blank ], :after =\u003e [ { :truncate =\u003e { :length =\u003e 11, :omission =\u003e '' } } ] do |value|\n    value.present? \u0026\u0026 value.is_a?(String) ? value.downcase.gsub(/\\s+/, '-') : value\n  end\n\nend\u003c/code\u003e\u003c/pre\u003e\n\np. All the specs will pass now.  Here is quick look at the behaviour from a console.\n\n\u003cpre\u003e\u003ccode\u003esummary = 'Here is my summary that is a little to long'\ntitle   = 'pick up chicks with magic tricks'\nbook    = Book.create!(:author =\u003e '', :price =\u003e '$3,450.89', :summary =\u003e summary, :title =\u003e title, :slug =\u003e title, :limited_slug =\u003e title)\nbook.author       # =\u003e nil\nbook.price        # =\u003e 3450.89\nbook.summary      # =\u003e 'Here is m...'\nbook.title        # =\u003e 'Pick Up Chicks With Magic Tricks'\nbook.slug         # =\u003e 'pick-up-chicks-with-magic-tricks'\nbook.limited_slug # =\u003e 'pick-up-chi'\n\u003c/code\u003e\u003c/pre\u003e\n\nh2. Test Helpers\n\np. If you are running RSpec there is a matcher available for use.  Usage can been seen above.  Include it as follows.\n\nh3. Rails 2\n\n\u003cpre\u003e\u003ccode\u003e# spec/spec_helper.rb\nRSpec.configure do |config|\n  config.include AttributeNormalizer::RSpecMatcher, :type =\u003e :models\nend\u003c/code\u003e\u003c/pre\u003e\n\nh3. Rails 3\n\n\u003cpre\u003e\u003ccode\u003e# spec/spec_helper.rb\nRSpec.configure do |config|\n  config.include AttributeNormalizer::RSpecMatcher, :type =\u003e :model\nend\u003c/code\u003e\u003c/pre\u003e\n\np. _I will gladly take a patch to add a macro to Test::Unit if someone submits it._\n\nh2. Credits\n\nOriginal module code and concept was taken from \"Dan Kubb\":http://github.com/dkubb during a project we worked on together.  I found that I was consistently using this across all my projects so I wanted to plugin-er-size and gem this up for easy reuse.\n\nh2. Copyright\n\nCopyright (c) 2009-2010 \"Michael Deering(Edmonton Ruby on Rails)\":http://mdeering.com See MIT-LICENSE for details.\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdeering%2Fattribute_normalizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmdeering%2Fattribute_normalizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdeering%2Fattribute_normalizer/lists"}