Class: FeatureType

Inherits:
Object
  • Object
show all
Includes:
EnumField::DefineEnum
Defined in:
app/models/enums/feature_type.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  @code = code.to_sym
  @type = type.to_sym
  @options = options
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



6
7
8
# File 'app/models/enums/feature_type.rb', line 6

def code
  @code
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'app/models/enums/feature_type.rb', line 6

def options
  @options
end

#typeObject (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

.extrasObject



45
46
47
# File 'app/models/enums/feature_type.rb', line 45

def extras
  all.select(&:extras?)
end

Instance Method Details

#descriptionObject



18
19
20
# File 'app/models/enums/feature_type.rb', line 18

def description
  I18n.t(code, scope: [:feature_type, :description])
end

#extras?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/models/enums/feature_type.rb', line 40

def extras?
  @type == :extras
end

#multiple_variants?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


32
33
34
# File 'app/models/enums/feature_type.rb', line 32

def show?
  @type == :extras
end

#titleObject



14
15
16
# File 'app/models/enums/feature_type.rb', line 14

def title
  I18n.t(code, scope: [:feature_type, :title])
end