Class Vpim::DirectoryInfo
In: lib/vpim/dirinfo.rb
lib/vpim/field.rb
Parent: Object

An RFC 2425 directory info object.

A directory information object is a sequence of fields. The basic structure of the object, and the way in which it is broken into fields is common to all profiles of the directory info type.

A vCard, for example, is a specialization of a directory info object.

Here‘s an example of encoding a simple vCard using the low-level APIs:

  card = Vpim::Vcard.create
  card << Vpim::DirectoryInfo::Field.create('EMAIL', 'user.name@example.com', 'TYPE' => 'INTERNET' )
  card << Vpim::DirectoryInfo::Field.create('URL', 'http://www.example.com/user' )
  card << Vpim::DirectoryInfo::Field.create('FN', 'User Name' )
  puts card.to_s

Don‘t do it like that, use Vpim::Vcard::Maker.

Methods

<<   []   create   delete   each   encode   enum_by_cond   enum_by_group   enum_by_name   field   groups   push   push_end   push_unique   text   to_s  

Included Modules

Enumerable

Classes and Modules

Class Vpim::DirectoryInfo::Field

Public Class methods

Create a new DirectoryInfo object. The fields are an optional array of DirectoryInfo::Field objects to add to the new object, between the BEGIN/END. If the profile string is not nil, then it is the name of the directory info profile, and the BEGIN:profile/END:profile fields will be added.

A DirectoryInfo is mutable, you can add new fields to it using push(), and see Field#create().

Public Instance methods

<<(field)

Alias for push

The value of the first field named name, or nil if no match is found.

Delete field.

Warning: You can‘t delete BEGIN: or END: fields, but other profile-specific fields can be deleted, including mandatory ones. For vCards in particular, in order to avoid destroying them, I suggest creating a new Vcard, and copying over all the fields that you still want, rather than using delete. This is easy with Vcard::Maker#copy, see the Vcard::Maker examples.

Yields for each Field for which cond.call(field) is true. The (default) cond of nil is considered true for all fields, so this acts like a normal each() when called with no arguments.

The string encoding of the DirectoryInfo. See Field#encode for information about the width parameter.

Returns an Enumerator for each Field for which cond.call(field) is true.

Returns an Enumerator for each Field for which group?(group) is true.

For example, to print all the fields, sorted by group, you could do:

  card.groups.sort.each do |group|
    card.enum_by_group(group).each do |field|
      puts "#{group} -> #{field.name}"
    end
  end

or to get an array of all the fields in group ‘AGROUP’, you could do:

  card.enum_by_group('AGROUP').to_a

Returns an Enumerator for each Field for which name?(name) is true.

An Enumerator supports all the methods of Enumerable, so it allows iteration, collection, mapping, etc.

Examples:

Print all the nicknames in a card:

  card.enum_by_name('NICKNAME') { |f| puts f.value }

Print an Array of the preferred email addresses in the card:

  pref_emails = card.enum_by_name('EMAIL').select { |f| f.pref? }

The first field named name, or nil if no match is found.

Array of all the Field#group()s.

Append field to the fields. Note that it won‘t be literally appended to the fields, it will be inserted before the closing END field.

Append field to the end of all the fields. This isn‘t usually what you want to do, usually a DirectoryInfo‘s first and last fields are a BEGIN/END pair, see push().

Push field onto the fields, unless there is already a field with this name.

An array of all the values of fields named name, converted to text (using Field#to_text()).

TODO - call this texts(), as in the plural?

to_s(width=nil)

Alias for encode

[Validate]