Class: Vpim::Vcard::Telephone

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

Overview

Represents the value of a TEL field.

The value is supposed to be a “X.500 Telephone Number” according to RFC 2426, but that standard is not freely available. Otherwise, anything that looks like a phone number should be OK.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(telephone = '') ⇒ Telephone

:nodoc:



293
294
295
296
297
298
299
# File 'lib/vpim/vcard.rb', line 293

def initialize(telephone='') #:nodoc:
  @preferred = false
  @location = []
  @capability = []
  @nonstandard = []
  super(telephone)
end

Instance Attribute Details

#capabilityObject

voice, fax, video, msg, bbs, modem, isdn, pcs (Array of String): the capabilities of the device



288
289
290
# File 'lib/vpim/vcard.rb', line 288

def capability
  @capability
end

#locationObject

home, work, cell, car, pager (Array of String): the location of the device



285
286
287
# File 'lib/vpim/vcard.rb', line 285

def location
  @location
end

#nonstandardObject (readonly)

nonstandard types, their meaning is undefined (Array of String). These might be found during decoding, but shouldn’t be set during encoding.



291
292
293
# File 'lib/vpim/vcard.rb', line 291

def nonstandard
  @nonstandard
end

#preferredObject

true, false (boolean): whether this is the preferred email address



282
283
284
# File 'lib/vpim/vcard.rb', line 282

def preferred
  @preferred
end

Class Method Details

.decode(field) ⇒ Object

:nodoc:



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/vpim/vcard.rb', line 329

def Telephone.decode(field) #:nodoc:
  value = field.to_text.strip

  if value.length < 1
    raise InvalidEncodingError, "TEL must have a value"
  end

  tel = Telephone.new(value)

  params = field.pvalues('TYPE')

  if params
    params.each do |p|
      p.downcase!
      case p
      when 'home', 'work', 'cell', 'car', 'pager'
        tel.location << p
      when 'voice', 'fax', 'video', 'msg', 'bbs', 'modem', 'isdn', 'pcs'
        tel.capability << p
      when 'pref'
        tel.preferred = true
      else
        tel.nonstandard << p
      end
    end
    # Strip duplicates
    [ tel.location, tel.capability, tel.nonstandard ].each do |a|
      a.uniq!
    end
  end

  tel
end

Instance Method Details

#encodeObject

:nodoc:



310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/vpim/vcard.rb', line 310

def encode #:nodoc:
  value = to_str.strip

  if value.length < 1
    raise InvalidEncodingError, "TEL must have a value"
  end

  params = [ @location, @capability, @nonstandard ]
  params << 'pref'  if @preferred

  params = params.flatten.compact.map { |s| s.to_str.downcase }.uniq

  paramshash = {}

  paramshash['TYPE'] = params if params.first

  Vpim::DirectoryInfo::Field.create( 'TEL', value, paramshash)
end

#inspectObject

:nodoc:



301
302
303
304
305
306
307
308
# File 'lib/vpim/vcard.rb', line 301

def inspect #:nodoc:
  s = "#<#{self.class.to_s}: #{to_str.inspect}"
  s << ", pref" if preferred
  s << ", " << @location.join(", ") if @location.first
  s << ", " << @capability.join(", ") if @capability.first
  s << ", #{@nonstandard.join(", ")}" if @nonstandard.first
  s
end