Skip to content

Commit

Permalink
Add method GDPRCompliant to Country data type
Browse files Browse the repository at this point in the history
  • Loading branch information
pioz committed Oct 6, 2023
1 parent 71ab335 commit ac8f8b4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions country.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ func (c *Country) FormatAddress(recipient, street, postalCode, city, region stri
return a
}

// GDPRCompliant returns true if the country is GDPR (General Data Protection
// Regulation) compliant. A country is GDPR compliant if is a member of the
// European Economic Area or it is UK.
func (c *Country) GDPRCompliant() bool {
return c.EEAMember || c.Alpha2 == "GB"
}

var flagsCodePoints = map[rune]rune{
'a': '🇦',
'b': '🇧',
Expand Down
17 changes: 17 additions & 0 deletions country_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,23 @@ func ExampleCountry_FormatAddress() {
// United States of America
}

func ExampleCountry_GDPRCompliant() {
c := countries.Get("IT")
fmt.Println(c.GDPRCompliant())
// Output: true
}

func TestGDPRCompliant(t *testing.T) {
c := countries.Get("IT")
assert.True(t, c.GDPRCompliant())

c = countries.Get("GB")
assert.True(t, c.GDPRCompliant())

c = countries.Get("US")
assert.False(t, c.GDPRCompliant())
}

func ExampleCountry_EmojiFlag() {
c := countries.Get("US")
fmt.Println(c.EmojiFlag())
Expand Down

0 comments on commit ac8f8b4

Please sign in to comment.