type-humanizer 0.0.2 → 0.0.3
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 +4 -4
- data/README.md +45 -3
- data/lib/humanizer.rb +1 -1
- data/lib/humanizer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aeaef0b54d823153c2202e8cbf9a3536c9864ed8
|
4
|
+
data.tar.gz: bcf0b0123f80d1ef0239c579bb005e4ce7f87778
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 958cc0661fdb64d0e41fb096ef9533165cbc450659c12cb8d35b1d3e25a4cffe80346aaa1964bc966f4e6a11ad2a031ad4039733709f6ce62f5289973d47c5c0
|
7
|
+
data.tar.gz: 926ed3f3c450341309c36ce0265f8a213482ba0f9201e5e56bb40bf030c9e8c559875eeae3be70b4be5a5ce6042a0e79f3aca0c63e96281c01242a0bdc1e2cb6
|
data/README.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
# Humanizer
|
2
2
|
|
3
|
-
|
3
|
+
A library for humazing and sanitizing array and hash
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
|
9
|
+
```ruby
|
10
|
+
gem 'type-humanizer'
|
11
|
+
```
|
10
12
|
|
11
13
|
And then execute:
|
12
14
|
|
@@ -18,7 +20,46 @@ Or install it yourself as:
|
|
18
20
|
|
19
21
|
## Usage
|
20
22
|
|
21
|
-
|
23
|
+
### Humanizing
|
24
|
+
|
25
|
+
We can humanize `Array` and `Hash`
|
26
|
+
|
27
|
+
To do that, we just call `Humanizer::Human#from`
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Humanizer::Human.from ['a', 'b', 'c']
|
31
|
+
=> "a, b, c"
|
32
|
+
|
33
|
+
Humanizer::Human.from { :foo => 'bar', :boo => 'baz' }
|
34
|
+
=> "foo: bar, boo: baz"
|
35
|
+
```
|
36
|
+
|
37
|
+
### Sanitizing
|
38
|
+
Again, we can sanitize `Array` and `Hash`
|
39
|
+
|
40
|
+
This time we need the `Humanizer::Sanitize` class
|
41
|
+
```ruby
|
42
|
+
sanitizer = Humanizer::Sanitize.new
|
43
|
+
|
44
|
+
sanitizer.to_array 'a, b, c'
|
45
|
+
=> ["a", "b", "c"]
|
46
|
+
|
47
|
+
sanitizer.to_hash 'foo: bar, boo: baz'
|
48
|
+
=> { "foo" => "bar", "boo" => "baz" }
|
49
|
+
```
|
50
|
+
|
51
|
+
We can also sanitize a hash of params.. This could be some Rails params
|
52
|
+
|
53
|
+
All we need to do is pass the params and specify which params should be sanitized to what type
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
params = { friends: 'Jack, Jill', favorites: 'drink: Coffee, fruit: Bananas' }
|
57
|
+
|
58
|
+
Humanizer::Sanitize.params params, friends: :array, favorites: :hash
|
59
|
+
=> { :friends => ["Jack", "Jill"], :favorites => { "drink" => "Coffee", "fruit" => "Banana" } }
|
60
|
+
```
|
61
|
+
|
62
|
+
|
22
63
|
|
23
64
|
## Contributing
|
24
65
|
|
@@ -27,3 +68,4 @@ TODO: Write usage instructions here
|
|
27
68
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
69
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
70
|
5. Create a new Pull Request
|
71
|
+
|
data/lib/humanizer.rb
CHANGED
data/lib/humanizer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: type-humanizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aske Hansen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|