Module: ObjectEnum::EnumClassMethods
- Defined in:
- lib/object_enum/enum_class_methods.rb
Instance Method Summary collapse
-
#all ⇒ Array
Get all values.
-
#enum_class ⇒ Class
Returns the class that represents the value of the Enum.
-
#filter(attributes = {}) ⇒ Array
Returns a value that matches Hash.
-
#find(attributes = {}) ⇒ Object
Returns a value that matches Hash.
Instance Method Details
#all ⇒ Array
Get all values.
5 6 7 8 9 |
# File 'lib/object_enum/enum_class_methods.rb', line 5 def all self.constants(false) .map { |c| const_get(c) } .filter { |obj| obj.class.ancestors.include? enum_class } end |
#enum_class ⇒ Class
Returns the class that represents the value of the Enum.
13 14 15 |
# File 'lib/object_enum/enum_class_methods.rb', line 13 def enum_class self end |
#filter(attributes = {}) ⇒ Array
Returns a value that matches Hash.
30 31 32 33 34 35 36 |
# File 'lib/object_enum/enum_class_methods.rb', line 30 def filter(attributes = {}) unless attributes.respond_to? :each_pair raise ArgumentError, "You must pass a hash. But #{attributes.class} passed." end all.filter { |enum_value| match_all_attributes?(enum_value, attributes) } end |
#find(attributes = {}) ⇒ Object
Returns a value that matches Hash. If there is no match, nil is returned.
22 23 24 |
# File 'lib/object_enum/enum_class_methods.rb', line 22 def find(attributes = {}) filter(attributes).first end |