9ebca08b
Adam Lockhart
Initial commit
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# ChangeDispenserController Class
#### calculateChange(unitsTendered, price)
**unitsTendered:** An array of instances of some kind of MonetaryUnit subclass. You can assert that the units tendered all have the same currency and that the amount tendered is greater than price.
**price:** Number. You can assert that the units tendered match the currency for price, which is why price is just a number.
**Returns** true if change can succesfully be dispensed, otherwise returns false to issue a refund and cancel the product.
# ChangeDispenser Class
An instance of ChangeDispenser is programmed to physically know what change it has to dispense and physically how to dispense it. Assume that ChangeDispenser is a thin JavaScript layer over native code.
### Properties
For every currency unit available, the JavaScript layer dynamically defines properties that match the class name of the monetary units using Object.defineProperty. It defines the properties as read-only properties using getter methods that return new arrays.
The new arrays returned from these properties are not referenced internally. For example, `var availablePennies = someChangeDispenserInstance.UnitedStatesPennyUnit;` would give you an array containing instances of UnitedStatesPennyUnit.
### Methods
#### unitsAvailable(currency)
Describes the types of monetary units available to dispense.
**currency:** A String value for the currency, i.e. "USD".
**Returns** an array of objects describing the availablity of monetary units that match the curreny passed in, sorted in descending monetaryValue:
[
{
propertyName: String (i.e. "UnitedStatesPennyUnit"),
unitInfo: {
monetaryValue: Number,
currency: String,
currencySymbol: String
}
}
]
#### dispense(units)
Physically dispenses change for all of the monetary unit instances that you pass in.
**units:** An array of instances of some kind of MonetaryUnit subclass.
**Throws** an error synchronously if any instance does not exist in its Column Properties.
|