coded_options 0.1.7 → 0.1.8

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.md CHANGED
@@ -34,6 +34,15 @@ a plain Ruby object as follows:
34
34
  foo.type_id = 1
35
35
  foo.type #=> awesome
36
36
 
37
+ If the values are important to your application you can pass
38
+ a hash instead of an array like so:
39
+
40
+ coded_options :gender, {99 => 'other', 1 => 'male', 2 => 'female'}
41
+
42
+ GENDER will return a hash (the exact hash above), not an array. GENDER_OPTIONS
43
+ will return an array suitable for select tags. The array will be ordered
44
+ numerically by the keys of the hash.
45
+
37
46
  If you want to use this with MongoDB, just add
38
47
 
39
48
  extend CodedOptions
@@ -25,7 +25,11 @@ module CodedOptions
25
25
  end
26
26
 
27
27
  def to_options values
28
- values.zip((0..values.length).to_a)
28
+ if values.is_a? Hash
29
+ values.sort{|a,b| a.first <=> b.first}.map{|a| a.reverse}
30
+ else
31
+ values.zip((0..values.length).to_a)
32
+ end
29
33
  end
30
34
 
31
35
  end
@@ -1,3 +1,3 @@
1
1
  module CodedOptions
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coded_options
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 7
10
- version: 0.1.7
9
+ - 8
10
+ version: 0.1.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jason Dew
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-19 00:00:00 -05:00
18
+ date: 2010-12-16 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies: []
21
21