type-humanizer 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94441bb261b664b050d691e742937cee4a660084
4
- data.tar.gz: b6f767ada57a7405fc9cb6463b727a9f4ce0573b
3
+ metadata.gz: aeaef0b54d823153c2202e8cbf9a3536c9864ed8
4
+ data.tar.gz: bcf0b0123f80d1ef0239c579bb005e4ce7f87778
5
5
  SHA512:
6
- metadata.gz: 47db09f56abe66f98180bc7a3b31eec13ea5fa2857d943d376f4503abc29213a40343ef20a501c8345fe8b06ad33eeda997e6decf53fe6f53434d3023b39706e
7
- data.tar.gz: a9141a44c408ac5f77fb3be381f315fa08b6ced19fda5c4688c969c563cdb72976b55148b63ccc4fa4172d4e6f7cb28ed17943dd71c921e8880cf5163254a727
6
+ metadata.gz: 958cc0661fdb64d0e41fb096ef9533165cbc450659c12cb8d35b1d3e25a4cffe80346aaa1964bc966f4e6a11ad2a031ad4039733709f6ce62f5289973d47c5c0
7
+ data.tar.gz: 926ed3f3c450341309c36ce0265f8a213482ba0f9201e5e56bb40bf030c9e8c559875eeae3be70b4be5a5ce6042a0e79f3aca0c63e96281c01242a0bdc1e2cb6
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # Humanizer
2
2
 
3
- TODO: Write a gem description
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
- gem 'type-humanizer'
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
- TODO: Write usage instructions here
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
@@ -41,7 +41,7 @@ module Humanizer
41
41
 
42
42
  class Human
43
43
  def self.from(value)
44
- type = String(value.class).downcase
44
+ type = String(value).class.downcase
45
45
  human = Human.new
46
46
 
47
47
  human.send "from_#{type}", value
@@ -1,3 +1,3 @@
1
1
  module Humanizer
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
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-27 00:00:00.000000000 Z
11
+ date: 2014-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler