Class: Vpim::Vcard::Email
- Inherits:
-
String
- Object
- String
- Vpim::Vcard::Email
- Defined in:
- lib/vpim/vcard.rb
Overview
Represents the value of an EMAIL field.
Instance Attribute Summary collapse
-
#format ⇒ Object
internet, x400 (String): the email address format, rarely specified since the default is ‘internet’.
-
#location ⇒ Object
home, work (Array of String): the location referred to by the address.
-
#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(email = '') ⇒ Email
constructor
:nodoc:.
-
#inspect ⇒ Object
:nodoc:.
Constructor Details
#initialize(email = '') ⇒ Email
:nodoc:
203 204 205 206 207 208 209 |
# File 'lib/vpim/vcard.rb', line 203 def initialize(email='') #:nodoc: @preferred = false @format = 'internet' @location = [] @nonstandard = [] super(email) end |
Instance Attribute Details
#format ⇒ Object
internet, x400 (String): the email address format, rarely specified since the default is ‘internet’
194 195 196 |
# File 'lib/vpim/vcard.rb', line 194 def format @format end |
#location ⇒ Object
home, work (Array of String): the location referred to by the address. The inclusion of location parameters in a vCard seems to be non-conformant, strictly speaking, but also seems to be widespread.
198 199 200 |
# File 'lib/vpim/vcard.rb', line 198 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.
201 202 203 |
# File 'lib/vpim/vcard.rb', line 201 def nonstandard @nonstandard end |
#preferred ⇒ Object
true, false (boolean): whether this is the preferred email address
191 192 193 |
# File 'lib/vpim/vcard.rb', line 191 def preferred @preferred end |
Class Method Details
.decode(field) ⇒ Object
:nodoc:
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/vpim/vcard.rb', line 240 def Email.decode(field) #:nodoc: value = field.to_text.strip if value.length < 1 raise InvalidEncodingError, "EMAIL must have a value" end eml = Email.new(value) params = field.pvalues('TYPE') if params params.each do |p| p.downcase! case p when 'home', 'work' eml.location << p when 'pref' eml.preferred = true when 'x400', 'internet' eml.format = p else eml.nonstandard << p end end # Strip duplicates [ eml.location, eml.nonstandard ].each do |a| a.uniq! end end eml end |
Instance Method Details
#encode ⇒ Object
:nodoc:
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/vpim/vcard.rb', line 220 def encode #:nodoc: value = to_str.strip if value.length < 1 raise InvalidEncodingError, "EMAIL must have a value" end params = [ @location, @nonstandard ] params << @format if @format != 'internet' 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( 'EMAIL', value, paramshash) end |
#inspect ⇒ Object
:nodoc:
211 212 213 214 215 216 217 218 |
# File 'lib/vpim/vcard.rb', line 211 def inspect #:nodoc: s = "#<#{self.class.to_s}: #{to_str.inspect}" s << ", pref" if preferred s << ", #{format}" if format != 'internet' s << ", " << @location.join(", ") if @location.first s << ", #{@nonstandard.join(", ")}" if @nonstandard.first s end |