Blame view

README.md 2.05 KB
db2759f3   Adam Lockhart   Updated documenta...
1
  ## ChangeDispenserController Class
f952a2ac   Adam Lockhart   Updated documenta...
2
  Provides a simple API for the veding machine change dispenser.
9ebca08b   Adam Lockhart   Initial commit
3
  
db2759f3   Adam Lockhart   Updated documenta...
4
  ### Methods
9ebca08b   Adam Lockhart   Initial commit
5
6
  #### calculateChange(unitsTendered, price)
  
51780235   Adam Lockhart   Updated documenta...
7
  **unitsTendered:** An array of instances of some kind of MonetaryUnit subclass.  The units tendered all have the same currency and the amount tendered is greater than price.
db2759f3   Adam Lockhart   Updated documenta...
8
  
51780235   Adam Lockhart   Updated documenta...
9
  **price:** Number. The units tendered match the currency for price, which is why price is just a number.
9ebca08b   Adam Lockhart   Initial commit
10
  
f952a2ac   Adam Lockhart   Updated documenta...
11
  **Returns** true if change will successfully be dispensed, otherwise returns false to issue a refund and cancel the product.
9ebca08b   Adam Lockhart   Initial commit
12
  
db2759f3   Adam Lockhart   Updated documenta...
13
  ## ChangeDispenser Class
51780235   Adam Lockhart   Updated documenta...
14
  An instance of ChangeDispenser is programmed to physically know what change it has to dispense and physically how to dispense it.  ChangeDispenser is a thin JavaScript layer over native code.
9ebca08b   Adam Lockhart   Initial commit
15
16
17
  
  ### 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.
db2759f3   Adam Lockhart   Updated documenta...
18
  The new arrays returned from these properties are not referenced internally. For example, `someChangeDispenserInstance.UnitedStatesPennyUnit` would give you an array containing all available instances of UnitedStatesPennyUnit.
9ebca08b   Adam Lockhart   Initial commit
19
20
21
22
23
24
25
26
  
  ### 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:
db2759f3   Adam Lockhart   Updated documenta...
27
  ```
9ebca08b   Adam Lockhart   Initial commit
28
  [
db2759f3   Adam Lockhart   Updated documenta...
29
      // ...
9ebca08b   Adam Lockhart   Initial commit
30
  	{
db2759f3   Adam Lockhart   Updated documenta...
31
  		propertyName: String (i.e. "UnitedStatesDimeUnit"),
9ebca08b   Adam Lockhart   Initial commit
32
  		unitInfo: {
db2759f3   Adam Lockhart   Updated documenta...
33
34
35
  			monetaryValue: 0.1,
  			currency: "USD",
  			currencySymbol: "$"
9ebca08b   Adam Lockhart   Initial commit
36
  		}
db2759f3   Adam Lockhart   Updated documenta...
37
38
  	},
  	// ...
9ebca08b   Adam Lockhart   Initial commit
39
  ]
db2759f3   Adam Lockhart   Updated documenta...
40
  ```
9ebca08b   Adam Lockhart   Initial commit
41
42
43
44
45
46
  
  #### 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.
  
db2759f3   Adam Lockhart   Updated documenta...
47
  **Throws** an error synchronously if any instance is not in the monetary unit properties, i.e. `someChangeDispenserInstance.UnitedStatesPennyUnit`.