simpler_enum 0.1.3 → 0.2.0

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
@@ -25,6 +25,22 @@ Any class can include `SimplerEnum` and you can define an enumerated type like t
25
25
  ```ruby
26
26
  require "simpler_enum"
27
27
 
28
+ class Person
29
+ include SimplerEnum
30
+
31
+ simpler_enum mood: %i(awesome excellent great good fine)
32
+
33
+ def initialize(mood: :fine)
34
+ self.mood = mood
35
+ end
36
+ end
37
+ ```
38
+
39
+ Or,
40
+
41
+ ```ruby
42
+ require "simpler_enum"
43
+
28
44
  class Person
29
45
  include SimplerEnum
30
46
 
@@ -42,6 +58,8 @@ class Person
42
58
  end
43
59
  ```
44
60
 
61
+ Both are behave like this:
62
+
45
63
  ```ruby
46
64
  [1] pry(main)> Person.moods
47
65
  => {:awesome=>0, :excellent=>1, :great=>2, :good=>3, :fine=>4}
@@ -3,7 +3,17 @@ module SimplerEnum
3
3
  def initialize(klass, enum_name, enum_values)
4
4
  @klass = klass
5
5
  @enum_name = enum_name
6
- @enum_values = enum_values
6
+ @enum_values =
7
+ case
8
+ when enum_values.is_a?(Array)
9
+ enum_values.zip(0...enum_values.size).reduce({}) do |hash, (key, val)|
10
+ hash.merge!(key => val)
11
+ end
12
+ when enum_values.is_a?(Hash)
13
+ enum_values
14
+ else
15
+ fail ArgumentError
16
+ end
7
17
  end
8
18
 
9
19
  def execute!
@@ -1,3 +1,3 @@
1
1
  module SimplerEnum
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simpler_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: