Class: Vcard::Vcard::Telephone
- Inherits:
-
String
- Object
- String
- Vcard::Vcard::Telephone
- Defined in:
- lib/vcard/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:
283 284 285 286 287 288 289 |
# File 'lib/vcard/vcard.rb', line 283 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
278 279 280 |
# File 'lib/vcard/vcard.rb', line 278 def capability @capability end |
#location ⇒ Object
home, work, cell, car, pager (Array of String): the location of the device
275 276 277 |
# File 'lib/vcard/vcard.rb', line 275 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.
281 282 283 |
# File 'lib/vcard/vcard.rb', line 281 def nonstandard @nonstandard end |
#preferred ⇒ Object
true, false (boolean): whether this is the preferred email address
272 273 274 |
# File 'lib/vcard/vcard.rb', line 272 def preferred @preferred end |
Class Method Details
.decode(field) ⇒ Object
:nodoc:
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/vcard/vcard.rb', line 319 def Telephone.decode(field) #:nodoc: value = field.to_text.strip if value.length < 1 raise ::Vcard::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:
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/vcard/vcard.rb', line 300 def encode #:nodoc: value = to_str.strip if value.length < 1 raise ::Vcard::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 ::Vcard::DirectoryInfo::Field.create( "TEL", value, paramshash) end |
#inspect ⇒ Object
:nodoc:
291 292 293 294 295 296 297 298 |
# File 'lib/vcard/vcard.rb', line 291 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 |