Class: Vpim::Vcard::Name

Inherits:
Object
  • Object
show all
Defined in:
lib/vpim/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:



394
395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/vpim/vcard.rb', line 394

def initialize(n='', fn='') #:nodoc:
  n = Vpim.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



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

def additional
  @additional
end

#familyObject

family name, from N



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

def family
  @family
end

#formattedObject (readonly)

:nodoc:



382
383
384
# File 'lib/vpim/vcard.rb', line 382

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.



380
381
382
# File 'lib/vpim/vcard.rb', line 380

def fullname
  @fullname
end

#givenObject

given name, from N



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

def given
  @given
end

#prefixObject

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



374
375
376
# File 'lib/vpim/vcard.rb', line 374

def prefix
  @prefix
end

#suffixObject

such as “BFA”, from N



376
377
378
# File 'lib/vpim/vcard.rb', line 376

def suffix
  @suffix
end

Instance Method Details

#encodeObject

:nodoc:



409
410
411
412
413
# File 'lib/vpim/vcard.rb', line 409

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

#encode_fnObject

:nodoc:



414
415
416
417
418
419
420
# File 'lib/vpim/vcard.rb', line 414

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