Class: Vpim::Vcard::Telephone
- Inherits:
-
String
- Object
- String
- Vpim::Vcard::Telephone
- 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
-
#capability ⇒ Object
voice, fax, video, msg, bbs, modem, isdn, pcs (Array of String): the capabilities of the device.
-
#location ⇒ Object
home, work, cell, car, pager (Array of String): the location of the device.
-
#nonstandard ⇒ Object
readonly
nonstandard types, their meaning is undefined (Array of String).
-
#preferred ⇒ Object
true, false (boolean): whether this is the preferred email address.
Class Method Summary collapse
-
.decode(field) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#encode ⇒ Object
:nodoc:.
-
#initialize(telephone = '') ⇒ Telephone
constructor
:nodoc:.
-
#inspect ⇒ Object
:nodoc:.
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
#capability ⇒ Object
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 |
#location ⇒ Object
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 |
#nonstandard ⇒ Object (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 |
#preferred ⇒ Object
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
#encode ⇒ Object
: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 |
#inspect ⇒ Object
: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 |