Blame view

README.md 1.98 KB
db2759f3   Adam Lockhart   Updated documenta...
1
  ## ChangeDispenserController Class
9ebca08b   Adam Lockhart   Initial commit
2
  
db2759f3   Adam Lockhart   Updated documenta...
3
  ### Methods
9ebca08b   Adam Lockhart   Initial commit
4
5
  #### calculateChange(unitsTendered, price)
  
51780235   Adam Lockhart   Updated documenta...
6
  **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...
7
  
51780235   Adam Lockhart   Updated documenta...
8
  **price:** Number. The units tendered match the currency for price, which is why price is just a number.
9ebca08b   Adam Lockhart   Initial commit
9
10
11
  
  **Returns** true if change can succesfully be dispensed, otherwise returns false to issue a refund and cancel the product.
  
db2759f3   Adam Lockhart   Updated documenta...
12
  ## ChangeDispenser Class
51780235   Adam Lockhart   Updated documenta...
13
  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
14
15
16
  
  ### 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...
17
  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
18
19
20
21
22
23
24
25
  
  ### 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...
26
  ```
9ebca08b   Adam Lockhart   Initial commit
27
  [
db2759f3   Adam Lockhart   Updated documenta...
28
      // ...
9ebca08b   Adam Lockhart   Initial commit
29
  	{
db2759f3   Adam Lockhart   Updated documenta...
30
  		propertyName: String (i.e. "UnitedStatesDimeUnit"),
9ebca08b   Adam Lockhart   Initial commit
31
  		unitInfo: {
db2759f3   Adam Lockhart   Updated documenta...
32
33
34
  			monetaryValue: 0.1,
  			currency: "USD",
  			currencySymbol: "$"
9ebca08b   Adam Lockhart   Initial commit
35
  		}
db2759f3   Adam Lockhart   Updated documenta...
36
37
  	},
  	// ...
9ebca08b   Adam Lockhart   Initial commit
38
  ]
db2759f3   Adam Lockhart   Updated documenta...
39
  ```
9ebca08b   Adam Lockhart   Initial commit
40
41
42
43
44
45
  
  #### 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...
46
  **Throws** an error synchronously if any instance is not in the monetary unit properties, i.e. `someChangeDispenserInstance.UnitedStatesPennyUnit`.