0.0
No commit activity in last 3 years
No release in over 3 years
A library for humazing and sanitizing array and hash
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.6
>= 0
 Project Readme

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