Class: SimpleEnumeration::Type
- Inherits:
-
Object
- Object
- SimpleEnumeration::Type
- Defined in:
- lib/simple_enumeration/type.rb
Constant Summary collapse
- VALUE_METHOD_NAME_SUFFIX =
'_value'
- VALUE_PREDICATE_METHOD_NAME_SUFFIX =
'_value?'
Instance Attribute Summary collapse
-
#converted_value ⇒ Object
readonly
Returns the value of attribute converted_value.
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#enum_class ⇒ Object
readonly
Returns the value of attribute enum_class.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
- .type_value_for_method_name(method_name) ⇒ Object
- .type_value_for_value_method_name(method_name) ⇒ Object
- .type_value_for_value_predicate_method_name(method_name) ⇒ Object
Instance Method Summary collapse
- #for_select ⇒ Object
- #humanized ⇒ Object
-
#initialize(definition:, value:, converted_value:, enum_class:) ⇒ Type
constructor
A new instance of Type.
- #meta ⇒ Object
- #method_name ⇒ Object
- #translations ⇒ Object
- #value_method_name ⇒ Object
- #value_predicate_method_name ⇒ Object
Constructor Details
#initialize(definition:, value:, converted_value:, enum_class:) ⇒ Type
Returns a new instance of Type.
7 8 9 10 11 12 |
# File 'lib/simple_enumeration/type.rb', line 7 def initialize(definition:, value:, converted_value:, enum_class:) @definition = definition @value = value @converted_value = converted_value @enum_class = enum_class end |
Instance Attribute Details
#converted_value ⇒ Object (readonly)
Returns the value of attribute converted_value.
5 6 7 |
# File 'lib/simple_enumeration/type.rb', line 5 def converted_value @converted_value end |
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
5 6 7 |
# File 'lib/simple_enumeration/type.rb', line 5 def definition @definition end |
#enum_class ⇒ Object (readonly)
Returns the value of attribute enum_class.
5 6 7 |
# File 'lib/simple_enumeration/type.rb', line 5 def enum_class @enum_class end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/simple_enumeration/type.rb', line 5 def value @value end |
Class Method Details
.type_value_for_method_name(method_name) ⇒ Object
17 18 19 |
# File 'lib/simple_enumeration/type.rb', line 17 def self.type_value_for_method_name(method_name) method_name.to_s end |
.type_value_for_value_method_name(method_name) ⇒ Object
21 22 23 |
# File 'lib/simple_enumeration/type.rb', line 21 def self.type_value_for_value_method_name(method_name) method_name.to_s.gsub(VALUE_METHOD_NAME_SUFFIX, '') end |
.type_value_for_value_predicate_method_name(method_name) ⇒ Object
25 26 27 |
# File 'lib/simple_enumeration/type.rb', line 25 def self.type_value_for_value_predicate_method_name(method_name) method_name.to_s.gsub(VALUE_PREDICATE_METHOD_NAME_SUFFIX, '') end |
Instance Method Details
#for_select ⇒ Object
41 42 43 |
# File 'lib/simple_enumeration/type.rb', line 41 def for_select [humanized, converted_value] end |
#humanized ⇒ Object
45 46 47 |
# File 'lib/simple_enumeration/type.rb', line 45 def humanized translations[:text] end |
#meta ⇒ Object
49 50 51 |
# File 'lib/simple_enumeration/type.rb', line 49 def translations.except(:text) end |
#method_name ⇒ Object
29 30 31 |
# File 'lib/simple_enumeration/type.rb', line 29 def method_name value end |
#translations ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/simple_enumeration/type.rb', line 53 def translations I18n.t( value, raise: true, scope: enum_class.i18n_scope ) end |
#value_method_name ⇒ Object
33 34 35 |
# File 'lib/simple_enumeration/type.rb', line 33 def value_method_name [value, VALUE_METHOD_NAME_SUFFIX].join end |
#value_predicate_method_name ⇒ Object
37 38 39 |
# File 'lib/simple_enumeration/type.rb', line 37 def value_predicate_method_name [value, VALUE_PREDICATE_METHOD_NAME_SUFFIX].join end |