Skip to content

Bg/#67/support email and phone types without type kw#73

Open
ManolisKoufidakis wants to merge 2 commits intobolorundurowb:masterfrom
ManolisKoufidakis:bg/#67/supportEmailAndPhoneTypesWithoutTypeKw
Open

Bg/#67/support email and phone types without type kw#73
ManolisKoufidakis wants to merge 2 commits intobolorundurowb:masterfrom
ManolisKoufidakis:bg/#67/supportEmailAndPhoneTypesWithoutTypeKw

Conversation

@ManolisKoufidakis
Copy link

@ManolisKoufidakis ManolisKoufidakis commented Sep 30, 2024

Feature: Identify email and phone types when Type keyword is not present. This is to support proper v2.1 and v3.0 vcards.

Comment on lines 28 to +45
var (key, data) = DataSplitHelpers.SplitDatum(datum, '=');

if (key.EqualsIgnoreCase(FieldKeyConstants.TypeKey) && data != null)
if (key.EqualsIgnoreCase(FieldKeyConstants.PreferenceKey))
{
var emailTypes = data.Split(FieldKeyConstants.ConcatenationDelimiter);

type = emailTypes
.Select(parsedType => parsedType.ParseEmailAddressType())
.Aggregate(type, (current, emailType) => current.HasValue ? current.Value | emailType : emailType);
}
else if (key.EqualsIgnoreCase(FieldKeyConstants.PreferenceKey))
preference = 1;
continue;
}

var emailTypes = key.EqualsIgnoreCase(FieldKeyConstants.TypeKey) && data != null
? data.Split(',')
: key != null && data == null
? key.Split(';')
: null;

type = emailTypes?
.Select(parsedType => parsedType.ParseEmailAddressType())
.Where(parsedType => parsedType != null)
.Aggregate(type, (current, emailType) => current.HasValue ? current.Value | emailType : emailType);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ManolisKoufidakis I think this can be simplified using the helper methods

var (key, data) = DataSplitHelpers.ExtractKeyValue(metadatum, '=');

  if (key is null || key.EqualsIgnoreCase(FieldKeyConstants.TypeKey))
  {
      var parsedType = data.ParseEmailAddressType();
      type = type is null ? parsedType : type | parsedType;
  }
  else if (key.EqualsIgnoreCase(FieldKeyConstants.PreferenceKey))
                  pref = int.Parse(data);

Comment on lines +31 to +46
if (key.EqualsIgnoreCase(FieldKeyConstants.PreferenceKey))
{
if (string.IsNullOrWhiteSpace(data))
continue;

var typeGroup = data!.Split(FieldKeyConstants.ConcatenationDelimiter);
preference = 1;
continue;
}

foreach (var individualType in typeGroup)
{
var phoneType = individualType.ParseTelephoneNumberType();
var phoneTypes = key.EqualsIgnoreCase(FieldKeyConstants.TypeKey) && data != null
? data.Split(',')
: key != null && data == null
? key.Split(';')
: null;

if (phoneType.HasValue)
type = type.HasValue ? type.Value | phoneType : phoneType;
}
}
else if (key.EqualsIgnoreCase(FieldKeyConstants.PreferenceKey))
preference = 1;
type = phoneTypes?
.Select(parsedType => parsedType.ParseTelephoneNumberType())
.Where(parsedType => parsedType != null)
.Aggregate(type, (current, phoneType) => current.HasValue ? current.Value | phoneType : phoneType);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ManolisKoufidakis I think this can be simplified similar to the above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants