Class: FeatureType
- Inherits:
-
Object
- Object
- FeatureType
- Includes:
- EnumField::DefineEnum
- Defined in:
- app/models/enums/feature_type.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #description ⇒ Object
- #extras? ⇒ Boolean
-
#initialize(code, type = :default, options = {}) ⇒ FeatureType
constructor
A new instance of FeatureType.
- #multiple_variants? ⇒ Boolean
- #name(value = nil) ⇒ Object
- #show? ⇒ Boolean
- #title ⇒ Object
Constructor Details
#initialize(code, type = :default, options = {}) ⇒ FeatureType
Returns a new instance of FeatureType.
8 9 10 11 12 |
# File 'app/models/enums/feature_type.rb', line 8 def initialize(code, type = :default, = {}) @code = code.to_sym @type = type.to_sym @options = end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'app/models/enums/feature_type.rb', line 6 def code @code end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'app/models/enums/feature_type.rb', line 6 def @options end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'app/models/enums/feature_type.rb', line 6 def type @type end |
Class Method Details
.extras ⇒ Object
45 46 47 |
# File 'app/models/enums/feature_type.rb', line 45 def extras all.select(&:extras?) end |
Instance Method Details
#description ⇒ Object
18 19 20 |
# File 'app/models/enums/feature_type.rb', line 18 def description I18n.t(code, scope: [:feature_type, :description]) end |
#extras? ⇒ Boolean
40 41 42 |
# File 'app/models/enums/feature_type.rb', line 40 def extras? @type == :extras end |
#multiple_variants? ⇒ Boolean
36 37 38 |
# File 'app/models/enums/feature_type.rb', line 36 def multiple_variants? @options[:multiple_variants] end |
#name(value = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'app/models/enums/feature_type.rb', line 22 def name(value = nil) return title if value.blank? case @code when :writer_level then "#{title}: #{value}" else value end end |
#show? ⇒ Boolean
32 33 34 |
# File 'app/models/enums/feature_type.rb', line 32 def show? @type == :extras end |
#title ⇒ Object
14 15 16 |
# File 'app/models/enums/feature_type.rb', line 14 def title I18n.t(code, scope: [:feature_type, :title]) end |