Class: Spree::Stock::Adjuster
- Inherits:
-
Object
- Object
- Spree::Stock::Adjuster
- Defined in:
- app/models/spree/stock/adjuster.rb
Instance Attribute Summary collapse
-
#need ⇒ Object
Returns the value of attribute need.
-
#status ⇒ Object
Returns the value of attribute status.
-
#variant ⇒ Object
Returns the value of attribute variant.
Instance Method Summary collapse
- #adjust(item) ⇒ Object
- #fulfilled? ⇒ Boolean
-
#initialize(variant, quantity, status) ⇒ Adjuster
constructor
A new instance of Adjuster.
Constructor Details
#initialize(variant, quantity, status) ⇒ Adjuster
Returns a new instance of Adjuster.
8 9 10 11 12 |
# File 'app/models/spree/stock/adjuster.rb', line 8 def initialize(variant, quantity, status) @variant = variant @need = quantity @status = status end |
Instance Attribute Details
#need ⇒ Object
Returns the value of attribute need.
6 7 8 |
# File 'app/models/spree/stock/adjuster.rb', line 6 def need @need end |
#status ⇒ Object
Returns the value of attribute status.
6 7 8 |
# File 'app/models/spree/stock/adjuster.rb', line 6 def status @status end |
#variant ⇒ Object
Returns the value of attribute variant.
6 7 8 |
# File 'app/models/spree/stock/adjuster.rb', line 6 def variant @variant end |
Instance Method Details
#adjust(item) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'app/models/spree/stock/adjuster.rb', line 14 def adjust(item) if item.quantity >= need item.quantity = need @need = 0 elsif item.quantity < need @need -= item.quantity end end |
#fulfilled? ⇒ Boolean
23 24 25 |
# File 'app/models/spree/stock/adjuster.rb', line 23 def fulfilled? @need == 0 end |