cwyckoff-hash_builder 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/README.rdoc +31 -4
- data/lib/hash_builder.rb +3 -0
- metadata +2 -1
data/README.rdoc
CHANGED
@@ -11,7 +11,7 @@ Are you tired of ugly, cumbersome hashes cluttering up your Rails models and con
|
|
11
11
|
== Examples
|
12
12
|
|
13
13
|
|
14
|
-
===
|
14
|
+
=== Defining
|
15
15
|
|
16
16
|
Let's say you want to build a hash of user contact information. In a separate file, set up a hash definition:
|
17
17
|
|
@@ -30,12 +30,18 @@ Let's say you want to build a hash of user contact information. In a separate f
|
|
30
30
|
bldr[:zip] = "04656"
|
31
31
|
end
|
32
32
|
|
33
|
+
bldr.build_hash(:personal) do
|
34
|
+
bldr[:gender] = "male"
|
35
|
+
bldr[:age] = "50"
|
36
|
+
bldr[:married] = false
|
37
|
+
end
|
38
|
+
|
33
39
|
end
|
34
40
|
|
35
41
|
|
36
42
|
=== Building
|
37
43
|
|
38
|
-
Each definition requires a key -- in this case :contact_info. Moreover, within the contact definition, you may set up namespaces (:name and :
|
44
|
+
Each definition requires a key -- in this case :contact_info. Moreover, within the contact definition, you may set up namespaces (:name, :address, and :personal) to further organize your hash content.
|
39
45
|
|
40
46
|
In order to build your hash, simply call
|
41
47
|
|
@@ -51,13 +57,16 @@ which will return
|
|
51
57
|
:city => "Crabapple Cove",
|
52
58
|
:state => "ME",
|
53
59
|
:zip => "04656",
|
60
|
+
:gender => "mail",
|
61
|
+
:age => "50",
|
62
|
+
:married => false,
|
54
63
|
}
|
55
64
|
|
56
65
|
If you want to build an individual namespace, call
|
57
66
|
|
58
67
|
HashBuilder.build_namespace(:contact_info, :address)
|
59
68
|
|
60
|
-
which will return only
|
69
|
+
which will return only the :address section of the hash
|
61
70
|
|
62
71
|
{
|
63
72
|
:street => "123 Main St.",
|
@@ -73,8 +82,20 @@ To select multiple namespaces, set them in a block:
|
|
73
82
|
b.using :address
|
74
83
|
end
|
75
84
|
|
85
|
+
which returns only the :name and :address sections of the hash
|
86
|
+
|
87
|
+
{
|
88
|
+
:title => "Dr.",
|
89
|
+
:f_name => "Hawkeye",
|
90
|
+
:l_name => "Pierce",
|
91
|
+
:street => "123 Main St.",
|
92
|
+
:city => "Crabapple Cove",
|
93
|
+
:state => "ME",
|
94
|
+
:zip => "04656",
|
95
|
+
}
|
76
96
|
|
77
|
-
|
97
|
+
|
98
|
+
=== Variables
|
78
99
|
|
79
100
|
You may pass additional variables to your hash definition when you build it. Simply pass them after the definition key.
|
80
101
|
|
@@ -101,6 +122,12 @@ All of this assumes that you will now yield the additional variables in the hash
|
|
101
122
|
bldr[:zip] = user.zip
|
102
123
|
end
|
103
124
|
|
125
|
+
bldr.build_hash(:personal) do |user|
|
126
|
+
bldr[:gender] = user.gender
|
127
|
+
bldr[:age] = user.age
|
128
|
+
bldr[:married] = user.married
|
129
|
+
end
|
130
|
+
|
104
131
|
end
|
105
132
|
|
106
133
|
|
data/lib/hash_builder.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cwyckoff-hash_builder
|
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
|
- Chris Wyckoff
|
@@ -24,6 +24,7 @@ extra_rdoc_files:
|
|
24
24
|
- MIT-LICENSE
|
25
25
|
files:
|
26
26
|
- init.rb
|
27
|
+
- lib/hash_builder.rb
|
27
28
|
- lib/hash_builder/hash_builder.rb
|
28
29
|
- README.rdoc
|
29
30
|
- MIT-LICENSE
|