Class: Para::Stall::VariantsPropertyConfig
- Inherits:
-
Object
- Object
- Para::Stall::VariantsPropertyConfig
- Defined in:
- lib/para/stall/variants_property_config.rb
Instance Attribute Summary collapse
-
#property ⇒ Object
readonly
Returns the value of attribute property.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#variants ⇒ Object
readonly
Returns the value of attribute variants.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #available_options ⇒ Object
- #current_value ⇒ Object
-
#initialize(resource, property, variants) ⇒ VariantsPropertyConfig
constructor
A new instance of VariantsPropertyConfig.
- #options ⇒ Object
- #property_value_for(variant) ⇒ Object
- #variant_property_value_for(variant) ⇒ Object
- #variant_property_value_or_build_for(variant) ⇒ Object
Constructor Details
#initialize(resource, property, variants) ⇒ VariantsPropertyConfig
Returns a new instance of VariantsPropertyConfig.
6 7 8 9 10 |
# File 'lib/para/stall/variants_property_config.rb', line 6 def initialize(resource, property, variants) @resource = resource @property = property @variants = variants end |
Instance Attribute Details
#property ⇒ Object (readonly)
Returns the value of attribute property.
4 5 6 |
# File 'lib/para/stall/variants_property_config.rb', line 4 def property @property end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
4 5 6 |
# File 'lib/para/stall/variants_property_config.rb', line 4 def resource @resource end |
#variants ⇒ Object (readonly)
Returns the value of attribute variants.
4 5 6 |
# File 'lib/para/stall/variants_property_config.rb', line 4 def variants @variants end |
Instance Method Details
#active? ⇒ Boolean
23 24 25 26 27 28 29 |
# File 'lib/para/stall/variants_property_config.rb', line 23 def active? variants.any? do |variant| variant.variant_property_values.any? do |variant_property_value| variant_property_value.property_value.try(:property) == property end end end |
#available_options ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/para/stall/variants_property_config.rb', line 37 def @available_options ||= property.property_values.each_with_object([]) do |property_value, ary| if property_value_used?(property_value) ary << [property_value.value, property_value.id] end end end |
#current_value ⇒ Object
31 32 33 34 35 |
# File 'lib/para/stall/variants_property_config.rb', line 31 def current_value @current_value ||= property.property_values.find do |property_value| property_value_used?(property_value) end end |
#options ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/para/stall/variants_property_config.rb', line 12 def property.property_values.map do |property_value| [ property_value.value, property_value.id, selected: property_value_used?(property_value), data: { name: property_value.value } ] end end |
#property_value_for(variant) ⇒ Object
45 46 47 |
# File 'lib/para/stall/variants_property_config.rb', line 45 def property_value_for(variant) variant_property_value_for(variant).try(:property_value) end |
#variant_property_value_for(variant) ⇒ Object
49 50 51 52 53 |
# File 'lib/para/stall/variants_property_config.rb', line 49 def variant_property_value_for(variant) variant_property_value = variant.variant_property_values.find do |variant_property_value| variant_property_value.property_value.try(:property) == property end end |
#variant_property_value_or_build_for(variant) ⇒ Object
55 56 57 |
# File 'lib/para/stall/variants_property_config.rb', line 55 def variant_property_value_or_build_for(variant) variant_property_value_for(variant) || variant.variant_property_values.build end |