Class: Vcard::Vcard::Name

Inherits:
Object
  • Object
show all
Defined in:
lib/vcard/vcard.rb

Overview

The name from a vCard, including all the components of the N: and FN: fields.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(n = "", fn = "") ⇒ Name

:nodoc:



383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/vcard/vcard.rb', line 383

def initialize(n="", fn="") #:nodoc:
  n = ::Vcard.decode_text_list(n, ";") do |item|
    item.strip
  end

  @family     = n[0] || ""
  @given      = n[1] || ""
  @additional = n[2] || ""
  @prefix     = n[3] || ""
  @suffix     = n[4] || ""

  # FIXME - make calls to #fullname fail if fn is nil
  @fullname = (fn || "").strip
end

Instance Attribute Details

#additionalObject

additional names, from N



361
362
363
# File 'lib/vcard/vcard.rb', line 361

def additional
  @additional
end

#familyObject

family name, from N



357
358
359
# File 'lib/vcard/vcard.rb', line 357

def family
  @family
end

#formattedObject (readonly)

:nodoc:



371
372
373
# File 'lib/vcard/vcard.rb', line 371

def formatted
  @formatted
end

#fullnameObject

full name, the FN field. FN is a formatted version of the N field, intended to be in a form more aligned with the cultural conventions of the vCard owner than formatted is.



369
370
371
# File 'lib/vcard/vcard.rb', line 369

def fullname
  @fullname
end

#givenObject

given name, from N



359
360
361
# File 'lib/vcard/vcard.rb', line 359

def given
  @given
end

#prefixObject

such as “Ms.” or “Dr.”, from N



363
364
365
# File 'lib/vcard/vcard.rb', line 363

def prefix
  @prefix
end

#suffixObject

such as “BFA”, from N



365
366
367
# File 'lib/vcard/vcard.rb', line 365

def suffix
  @suffix
end

Instance Method Details

#encodeObject

:nodoc:



398
399
400
# File 'lib/vcard/vcard.rb', line 398

def encode #:nodoc:
  ::Vcard::DirectoryInfo::Field.create("N", ::Vcard.encode_text_list([ @family, @given, @additional, @prefix, @suffix ].map{|n| n.strip}, ";"))
end

#encode_fnObject

:nodoc:



402
403
404
405
406
407
408
# File 'lib/vcard/vcard.rb', line 402

def encode_fn #:nodoc:
  fn = @fullname.strip
  if @fullname.length == 0
    fn = formatted
  end
  ::Vcard::DirectoryInfo::Field.create("FN", fn)
end