Implementation of a generic backend of eshop in Crystal
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.3 KiB

пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
  1. require "json"
  2. enum Country
  3. FR,
  4. NL,
  5. DE,
  6. IT,
  7. EI,
  8. GB,
  9. end
  10. class Address
  11. JSON.mapping(
  12. name: String,
  13. address1: String,
  14. address2: {type: String, nilable: true},
  15. postcode: String,
  16. city: String,
  17. country: Country,
  18. is_default: {type: Bool, default: false},
  19. )
  20. def <=> (other : Address)
  21. cmp = @name<=>other.name
  22. if cmp==0
  23. cmp = @address1<=>other.address1
  24. if cmp==0
  25. if @address2.nil?
  26. if(other.address2.nil?)
  27. cmp=0
  28. elsif
  29. cmp=-1
  30. end
  31. elsif other.address2.nil?
  32. cmp=1
  33. else
  34. cmp = @address2.not_nil!<=>other.address2.not_nil!
  35. end
  36. if cmp==0
  37. cmp = @postcode<=>other.postcode
  38. if cmp==0
  39. cmp = @city<=>other.city
  40. if cmp==0
  41. cmp = @country<=>other.country
  42. end
  43. end
  44. end
  45. end
  46. end
  47. return cmp
  48. end
  49. def == (other : Address)
  50. 0==(self<=>other)
  51. end
  52. def != (other : Address)
  53. 0!=(self<=>other)
  54. end
  55. end