yinum 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/enum.rb +5 -3
- data/yinum.gemspec +1 -1
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/lib/enum.rb
CHANGED
@@ -3,7 +3,7 @@ class Enum
|
|
3
3
|
include Enumerable
|
4
4
|
|
5
5
|
attr_reader :klass, :name, :by_name, :by_value
|
6
|
-
|
6
|
+
|
7
7
|
def initialize(name, klass=nil, hash={})
|
8
8
|
klass, hash = nil, klass if klass.is_a?(Hash)
|
9
9
|
@name, @klass = name, klass
|
@@ -32,7 +32,7 @@ class Enum
|
|
32
32
|
return name_or_values.map { |name_or_value| self[name_or_value] } if name_or_values.length > 1
|
33
33
|
|
34
34
|
name_or_value = name_or_values.first
|
35
|
-
ev = @
|
35
|
+
ev = @by_name_s[name_or_value.to_s] || @by_value_s[name_or_value.to_s]
|
36
36
|
raise "#{inspect} does not know #{name_or_value.inspect}" if ev.nil?
|
37
37
|
ev
|
38
38
|
end
|
@@ -41,12 +41,14 @@ class Enum
|
|
41
41
|
def map_hash(hash)
|
42
42
|
@by_name = {}
|
43
43
|
@by_value = {}
|
44
|
+
@by_name_s = {}
|
45
|
+
@by_value_s = {}
|
44
46
|
hash.each do |n, v|
|
45
47
|
n, v = v, n if v.is_a?(Symbol) or n.is_a?(Numeric)
|
46
48
|
raise "duplicate enum name #{n} for #{to_s}" if @by_name.has_key?(n)
|
47
49
|
raise "duplicate enum value #{v} for #{to_s}.#{n}" if @by_value.has_key?(v)
|
48
50
|
raise "value can't be nil for #{to_s}.#{n}" if v.nil?
|
49
|
-
@by_name[n] = @by_value[v] = EnumValue.new(self, n, v)
|
51
|
+
@by_name_s[n.to_s] = @by_value_s[v.to_s] = @by_name[n] = @by_value[v] = EnumValue.new(self, n, v)
|
50
52
|
end
|
51
53
|
@by_name.freeze
|
52
54
|
@by_value.freeze
|
data/yinum.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yinum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-23 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Yummy implementation of enum that gives integer values with a special
|
15
15
|
wrapping.
|