Class: Charger::Price

Inherits:
Object
  • Object
show all
Defined in:
lib/charger/price.rb

Instance Method Summary collapse

Instance Method Details

#between_quantities?(amount) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
# File 'lib/charger/price.rb', line 10

def between_quantities? amount
  if ending_quantity
    starting_quantity <= amount && ending_quantity >= amount
  else
    starting_quantity <= amount
  end
end

#remaining_quantity(amount) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/charger/price.rb', line 18

def remaining_quantity amount
  if ending_quantity
    amount - ending_quantity
  else
    amount
  end
end

#total(amount) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/charger/price.rb', line 26

def total amount
  return 0.0 if amount < starting_quantity
  if ending_quantity && amount > ending_quantity
    ending_quantity * unit_price
  else
    (amount - (starting_quantity-1)) * unit_price
  end
end