Class: Showroom::ProductVariant
- Defined in:
- lib/showroom/models/product_variant.rb
Overview
Represents a Shopify product variant.
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
-
#available? ⇒ Boolean
Returns true when the variant is available for purchase.
-
#on_sale? ⇒ Boolean
Returns true when
compare_at_priceis present and greater thanprice. -
#options ⇒ Array<String>
Returns the selected options for this variant as an Array of values.
Methods inherited from Resource
#==, #[], has_many, has_one, #initialize, #inspect, main_attr_keys, main_attrs, #method_missing, #respond_to_missing?, #to_h
Constructor Details
This class inherits a constructor from Showroom::Resource
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Showroom::Resource
Instance Method Details
#available? ⇒ Boolean
Returns true when the variant is available for purchase.
16 17 18 |
# File 'lib/showroom/models/product_variant.rb', line 16 def available? @attrs['available'] == true end |
#on_sale? ⇒ Boolean
Returns true when compare_at_price is present and greater than price.
23 24 25 26 27 28 |
# File 'lib/showroom/models/product_variant.rb', line 23 def on_sale? cap = @attrs['compare_at_price'] return false if cap.nil? || cap.to_s.empty? cap.to_f > @attrs['price'].to_f end |
#options ⇒ Array<String>
Returns the selected options for this variant as an Array of values.
Collects option1, option2, option3 in order, omitting nil values.
35 36 37 |
# File 'lib/showroom/models/product_variant.rb', line 35 def [@attrs['option1'], @attrs['option2'], @attrs['option3']].compact end |