hashify 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.
- data/VERSION +1 -1
- data/lib/hashify.rb +19 -4
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/hashify.rb
CHANGED
@@ -25,9 +25,17 @@ module Hashify
|
|
25
25
|
convert_map = assembled_hash_convert
|
26
26
|
instance = new
|
27
27
|
map.each do |name, val|
|
28
|
-
convert_map[name.to_sym]
|
29
|
-
|
28
|
+
if converter = convert_map[name.to_sym]
|
29
|
+
converted_val = case converter.last.arity
|
30
|
+
when 1: convert_map[name.to_sym].last.call(val)
|
31
|
+
when 2: convert_map[name.to_sym].last.call(val, instance)
|
32
|
+
else
|
33
|
+
raise 'arity must be 1 or 2'
|
34
|
+
end
|
35
|
+
instance.send((name.to_s + '=').to_sym, converted_val)
|
36
|
+
else
|
30
37
|
instance.send((name.to_s + '=').to_sym, val)
|
38
|
+
end
|
31
39
|
end
|
32
40
|
instance
|
33
41
|
end
|
@@ -46,9 +54,16 @@ module Hashify
|
|
46
54
|
|
47
55
|
def to_hash
|
48
56
|
self.class.assembled_hash_convert.inject({}) do |hash, (name, converter)|
|
49
|
-
converter
|
50
|
-
hash[name] = converter.first.
|
57
|
+
if converter
|
58
|
+
hash[name] = case converter.first.arity
|
59
|
+
when 1: converter.first.call(self.send(name))
|
60
|
+
when 2: converter.first.call(self.send(name), self)
|
61
|
+
else
|
62
|
+
raise 'arity must be 1 or 2'
|
63
|
+
end
|
64
|
+
else
|
51
65
|
hash[name] = self.send(name)
|
66
|
+
end
|
52
67
|
hash
|
53
68
|
end
|
54
69
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashify
|
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
|
- Joshua Hull
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-16 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|