Class: Spree::Stock::Adjuster

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/stock/adjuster.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#needObject

Returns the value of attribute need



6
7
8
# File 'app/models/spree/stock/adjuster.rb', line 6

def need
  @need
end

#statusObject

Returns the value of attribute status



6
7
8
# File 'app/models/spree/stock/adjuster.rb', line 6

def status
  @status
end

#variantObject

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

Returns:

  • (Boolean)


23
24
25
# File 'app/models/spree/stock/adjuster.rb', line 23

def fulfilled?
  @need == 0
end