type-humanizer 0.0.3 → 0.0.4
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 +12 -8
- data/lib/humanizer.rb +5 -1
- data/lib/humanizer/version.rb +1 -1
- data/test/human_test.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8234590cd5eb3a2667605c9a37d3e24497d6cfa2
|
4
|
+
data.tar.gz: fe8f6dfe78e92561b7af34adc361e9258fb2a735
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97a65c366989542fe891bc8c606e9718ad45337712ffe19fbdd76a22e495b4eff9a60dab4837bde3cd88ea6544b3e137acb9092bc4847a1bb0c7d13586694877
|
7
|
+
data.tar.gz: 3534e41be93911461e59a7882b1581b872ff52a7b96d8f97db84be439ca316ba1b90c853dc533344c82283ed0a94ab8d336e1a3309a8e265bfee0c622c38d3a0
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Humanizer
|
2
2
|
|
3
|
-
A library for humazing and sanitizing
|
3
|
+
A library for *humazing* and *sanitizing* `Array` and `Hash`
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -22,7 +22,9 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
### Humanizing
|
24
24
|
|
25
|
-
|
25
|
+
*First, lets humanize some data*
|
26
|
+
|
27
|
+
We can humanize an `Array` and a `Hash`
|
26
28
|
|
27
29
|
To do that, we just call `Humanizer::Human#from`
|
28
30
|
|
@@ -35,9 +37,13 @@ Humanizer::Human.from { :foo => 'bar', :boo => 'baz' }
|
|
35
37
|
```
|
36
38
|
|
37
39
|
### Sanitizing
|
38
|
-
Again, we can sanitize `Array` and `Hash`
|
39
40
|
|
40
|
-
|
41
|
+
*Now lets sanitize it*
|
42
|
+
|
43
|
+
Again, we can sanitize an `Array` and a `Hash`
|
44
|
+
|
45
|
+
For this we need the `Humanizer::Sanitize` class
|
46
|
+
|
41
47
|
```ruby
|
42
48
|
sanitizer = Humanizer::Sanitize.new
|
43
49
|
|
@@ -53,17 +59,15 @@ We can also sanitize a hash of params.. This could be some Rails params
|
|
53
59
|
All we need to do is pass the params and specify which params should be sanitized to what type
|
54
60
|
|
55
61
|
```ruby
|
56
|
-
params = { friends: 'Jack, Jill', favorites: 'drink: Coffee, fruit:
|
62
|
+
params = { friends: 'Jack, Jill', favorites: 'drink: Coffee, fruit: Banana' }
|
57
63
|
|
58
64
|
Humanizer::Sanitize.params params, friends: :array, favorites: :hash
|
59
65
|
=> { :friends => ["Jack", "Jill"], :favorites => { "drink" => "Coffee", "fruit" => "Banana" } }
|
60
66
|
```
|
61
67
|
|
62
|
-
|
63
|
-
|
64
68
|
## Contributing
|
65
69
|
|
66
|
-
1. Fork it ( https://github.com/
|
70
|
+
1. Fork it ( https://github.com/askehansen/humanizer/fork )
|
67
71
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
72
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
69
73
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/humanizer.rb
CHANGED
@@ -41,7 +41,7 @@ module Humanizer
|
|
41
41
|
|
42
42
|
class Human
|
43
43
|
def self.from(value)
|
44
|
-
type =
|
44
|
+
type = value.class.to_s.downcase
|
45
45
|
human = Human.new
|
46
46
|
|
47
47
|
human.send "from_#{type}", value
|
@@ -62,5 +62,9 @@ module Humanizer
|
|
62
62
|
|
63
63
|
value.join(', ')
|
64
64
|
end
|
65
|
+
|
66
|
+
def method_missing(name, *args)
|
67
|
+
args[0]
|
68
|
+
end
|
65
69
|
end
|
66
70
|
end
|
data/lib/humanizer/version.rb
CHANGED
data/test/human_test.rb
CHANGED
@@ -15,4 +15,9 @@ class HumanTest < Test::Unit::TestCase
|
|
15
15
|
assert_equal 'foo: bar, boo: baz', humanizer.from_hash({ foo: :bar, boo: :baz })
|
16
16
|
assert_equal '', humanizer.from_hash(nil)
|
17
17
|
end
|
18
|
+
|
19
|
+
def test_human_from
|
20
|
+
assert_equal 'foo', Humanizer::Human.from('foo')
|
21
|
+
assert_equal nil, Humanizer::Human.from(nil)
|
22
|
+
end
|
18
23
|
end
|