Ingredient.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. class Ingredient{
  2. constructor(id, name, category, unitType, unit, parent, specialUnit = undefined, unitSize = undefined){
  3. this._id = id;
  4. this._name = name;
  5. this._category = category;
  6. this._unitType = unitType;
  7. this._unit = unit;
  8. this._parent = parent;
  9. }
  10. get id(){
  11. return this._id;
  12. }
  13. get name(){
  14. return this._name;
  15. }
  16. set name(name){
  17. this._name = name;
  18. }
  19. get category(){
  20. return this._category;
  21. }
  22. set category(category){
  23. this._category = category;
  24. }
  25. get unitType(){
  26. return this._unitType;
  27. }
  28. get unit(){
  29. return this._unit;
  30. }
  31. set unit(unit){
  32. this._unit = unit;
  33. }
  34. get parent(){
  35. return this._parent;
  36. }
  37. get specialUnit(){
  38. return this._specialUnit;
  39. }
  40. get unitSize(){
  41. switch(this._unit){
  42. case "g":return this._unitSize;
  43. case "kg": return this._unitSize / 1000;
  44. case "oz": return this._unitSize / 28.3495;
  45. case "lb": return this._unitSize / 453.5924;
  46. case "ml": return this._unitSize * 1000;
  47. case "l": return this._unitSize;
  48. case "tsp": return this._unitSize * 202.8842;
  49. case "tbsp": return this._unitSize * 67.6278;
  50. case "ozfl": return this._unitSize * 33.8141;
  51. case "cup": return this._unitSize * 4.1667;
  52. case "pt": return this._unitSize * 2.1134;
  53. case "qt": return this._unitSize * 1.0567;
  54. case "gal": return this._unitSize / 3.7854;
  55. case "mm": return this._unitSize * 1000;
  56. case "cm": return this._unitSize * 100;
  57. case "m": return this._unitSize;
  58. case "in": return this._unitSize * 39.3701;
  59. case "ft": return this._unitSize * 3.2808;
  60. default: return this._unitSize;
  61. }
  62. }
  63. set unitSize(unitSize){
  64. if(unitSize < 0){
  65. return false;
  66. }
  67. this._unitSize = unitSize;
  68. }
  69. getBaseUnitSize(){
  70. return this._unitSize;
  71. }
  72. getNameAndUnit(){
  73. return `${this._name} (${this._unit.toUpperCase()})`;
  74. }
  75. }
  76. module.exports = Ingredient;