Class: SimpleEnumeration::Entity
- Inherits:
-
Object
- Object
- SimpleEnumeration::Entity
- Defined in:
- lib/simple_enumeration/entity.rb
Instance Attribute Summary collapse
-
#converted_value ⇒ Object
readonly
Returns the value of attribute converted_value.
Class Method Summary collapse
- .define_basic_collection(*definitions) ⇒ Object
- .define_custom_collection(collection_name, *types) ⇒ Object
- .get_collection(name) ⇒ Object
- .i18n_scope ⇒ Object
- .set_collection(name, value) ⇒ Object
Instance Method Summary collapse
-
#initialize(converted_value:) ⇒ Entity
constructor
A new instance of Entity.
- #type ⇒ Object
Constructor Details
#initialize(converted_value:) ⇒ Entity
Returns a new instance of Entity.
7 8 9 |
# File 'lib/simple_enumeration/entity.rb', line 7 def initialize(converted_value:) @converted_value = converted_value end |
Instance Attribute Details
#converted_value ⇒ Object (readonly)
Returns the value of attribute converted_value.
5 6 7 |
# File 'lib/simple_enumeration/entity.rb', line 5 def converted_value @converted_value end |
Class Method Details
.define_basic_collection(*definitions) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/simple_enumeration/entity.rb', line 18 def self.define_basic_collection(*definitions) Collections::BasicFactory.call( enum_class: self, definitions: definitions ) end |
.define_custom_collection(collection_name, *types) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/simple_enumeration/entity.rb', line 25 def self.define_custom_collection(collection_name, *types) Collections::CustomFactory.call( enum_class: self, collection_name: collection_name, types: types ) end |
.get_collection(name) ⇒ Object
33 34 35 |
# File 'lib/simple_enumeration/entity.rb', line 33 def self.get_collection(name) instance_variable_get("@#{name}") end |
.i18n_scope ⇒ Object
11 12 13 14 15 16 |
# File 'lib/simple_enumeration/entity.rb', line 11 def self.i18n_scope [ 'simple_enumeration', SimpleEnumeration.underscore(name.gsub('Enumeration', '')) ].join('.') end |
.set_collection(name, value) ⇒ Object
37 38 39 |
# File 'lib/simple_enumeration/entity.rb', line 37 def self.set_collection(name, value) instance_variable_set("@#{name}", value) end |
Instance Method Details
#type ⇒ Object
41 42 43 44 45 |
# File 'lib/simple_enumeration/entity.rb', line 41 def type @type ||= self.class.basic_collection.types.values.find do |type| type.converted_value.to_s == converted_value.to_s end end |