Implementation of a generic backend of eshop in Crystal
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

57 lignes
1.3 KiB

require "json"
enum Country
FR,
NL,
DE,
IT,
EI,
GB,
end
class Address
JSON.mapping(
name: String,
address1: String,
address2: {type: String, nilable: true},
postcode: String,
city: String,
country: Country,
is_default: {type: Bool, default: false},
)
def <=> (other : Address)
cmp = @name<=>other.name
if cmp==0
cmp = @address1<=>other.address1
if cmp==0
if @address2.nil?
if(other.address2.nil?)
cmp=0
elsif
cmp=-1
end
elsif other.address2.nil?
cmp=1
else
cmp = @address2.not_nil!<=>other.address2.not_nil!
end
if cmp==0
cmp = @postcode<=>other.postcode
if cmp==0
cmp = @city<=>other.city
if cmp==0
cmp = @country<=>other.country
end
end
end
end
end
return cmp
end
def == (other : Address)
0==(self<=>other)
end
def != (other : Address)
0!=(self<=>other)
end
end