GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - askehansen/humanizer: Humanize and sanitize array and hash

BranchesTags
Open more actions menu

Latest commit

 

History

28 Commits
28 Commits

Folders and files

NameName
Last commit message
Last commit date
lib
lib
 
 
test
test
 
 
.gitignore
.gitignore
 
 
Gemfile
Gemfile
 
 
LICENSE.txt
LICENSE.txt
 
 
README.md
README.md
 
 
Rakefile
Rakefile
 
 
humanizer.gemspec
humanizer.gemspec
 
 

Repository files navigation

Humanizer

A library for humazing and sanitizing Array and Hash

Installation

Add this line to your application's Gemfile:

gem 'type-humanizer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install type-humanizer

Usage

Humanizing

First, lets humanize some data

We can humanize an Array and a Hash

To do that, we just call Humanizer::Human#from

Humanizer::Human.from ['a', 'b', 'c']
=> "a, b, c"

Humanizer::Human.from { :foo => 'bar', :boo => 'baz' }
=> "foo: bar, boo: baz"

Sanitizing

Now lets sanitize it

Again, we can sanitize an Array and a Hash

For this we need the Humanizer::Sanitize class

sanitizer = Humanizer::Sanitize.new

sanitizer.to_array 'a, b, c'
=> ["a", "b", "c"]

sanitizer.to_hash 'foo: bar, boo: baz'
=> { "foo" => "bar", "boo" => "baz" }

We can also sanitize a hash of params.. This could be some Rails params

All we need to do is pass the params and specify which params should be sanitized to what type

params = { friends: 'Jack, Jill', favorites: 'drink: Coffee, fruit: Banana' }

Humanizer::Sanitize.params params, friends: :array, favorites: :hash
=> { :friends => ["Jack", "Jill"], :favorites => { "drink" => "Coffee", "fruit" => "Banana" } }

Configuration

You can configure the delimeters by creating an initializer:

Humanizer.configure do |config|
  # These are the default values
  config.array_delimeter   = ', '
  config.hash_delimeter    = ', '
  config.key_val_delimeter = ': '
end

Contributing

  1. Fork it ( https://github.com/askehansen/humanizer/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

About

Humanize and sanitize array and hash

Resources

Readme
MIT license
Activity

Stars

1 star

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.