Class: Vcard::Vcard::Address
- Inherits:
-
Object
- Object
- Vcard::Vcard::Address
- Defined in:
- lib/vcard/vcard.rb
Overview
Represents the value of an ADR field.
#location, #preferred, and #delivery indicate information about how the address is to be used, the other attributes are parts of the address.
Using values other than those defined for #location or #delivery is unlikely to be portable, or even conformant.
All attributes are optional. #location and #delivery can be set to arrays of strings.
Constant Summary collapse
- @@adr_parts =
Used to simplify some long and tedious code. These symbols are in the order required for the ADR field structured TEXT value, the order cannot be changed.
[ :@pobox, :@extended, :@street, :@locality, :@region, :@postalcode, :@country, ]
Instance Attribute Summary collapse
-
#country ⇒ Object
country name (String).
-
#delivery ⇒ Object
postal, parcel, dom (domestic), intl (international) (Array of String): delivery type of this address.
-
#extended ⇒ Object
seldom used, its not clear what it is for (String).
-
#locality ⇒ Object
usually the city (String).
-
#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).
-
#pobox ⇒ Object
post office box (String).
-
#postalcode ⇒ Object
postal code (String).
-
#preferred ⇒ Object
true, false (boolean): where this is the preferred address (for this location).
-
#region ⇒ Object
usually the province or state (String).
-
#street ⇒ Object
street address (String).
Class Method Summary collapse
-
.decode(card, field) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#encode ⇒ Object
:nodoc:.
-
#initialize ⇒ Address
constructor
TODO - #location? - #delivery?.
Constructor Details
#initialize ⇒ Address
TODO
-
#location?
-
#delivery?
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/vcard/vcard.rb', line 111 def initialize #:nodoc: # TODO - Add #label to support LABEL. Try to find LABEL # in either same group, or with sam params. @@adr_parts.each do |part| instance_variable_set(part, "") end @location = [] @preferred = false @delivery = [] @nonstandard = [] end |
Instance Attribute Details
#country ⇒ Object
country name (String)
82 83 84 |
# File 'lib/vcard/vcard.rb', line 82 def country @country end |
#delivery ⇒ Object
postal, parcel, dom (domestic), intl (international) (Array of String): delivery type of this address
89 90 91 |
# File 'lib/vcard/vcard.rb', line 89 def delivery @delivery end |
#extended ⇒ Object
seldom used, its not clear what it is for (String)
72 73 74 |
# File 'lib/vcard/vcard.rb', line 72 def extended @extended end |
#locality ⇒ Object
usually the city (String)
76 77 78 |
# File 'lib/vcard/vcard.rb', line 76 def locality @locality end |
#location ⇒ Object
home, work (Array of String): the location referred to by the address
84 85 86 |
# File 'lib/vcard/vcard.rb', line 84 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.
93 94 95 |
# File 'lib/vcard/vcard.rb', line 93 def nonstandard @nonstandard end |
#pobox ⇒ Object
post office box (String)
70 71 72 |
# File 'lib/vcard/vcard.rb', line 70 def pobox @pobox end |
#postalcode ⇒ Object
postal code (String)
80 81 82 |
# File 'lib/vcard/vcard.rb', line 80 def postalcode @postalcode end |
#preferred ⇒ Object
true, false (boolean): where this is the preferred address (for this location)
86 87 88 |
# File 'lib/vcard/vcard.rb', line 86 def preferred @preferred end |
#region ⇒ Object
usually the province or state (String)
78 79 80 |
# File 'lib/vcard/vcard.rb', line 78 def region @region end |
#street ⇒ Object
street address (String)
74 75 76 |
# File 'lib/vcard/vcard.rb', line 74 def street @street end |
Class Method Details
.decode(card, field) ⇒ Object
:nodoc:
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/vcard/vcard.rb', line 142 def Address.decode(card, field) #:nodoc: adr = new parts = ::Vcard.decode_text_list(field.value_raw, ";") @@adr_parts.each_with_index do |part,i| adr.instance_variable_set(part, parts[i] || "") end params = field.pvalues("TYPE") if params params.each do |p| p.downcase! case p when "home", "work" adr.location << p when "postal", "parcel", "dom", "intl" adr.delivery << p when "pref" adr.preferred = true else adr.nonstandard << p end end # Strip duplicates [ adr.location, adr.delivery, adr.nonstandard ].each do |a| a.uniq! end end adr end |
Instance Method Details
#encode ⇒ Object
:nodoc:
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/vcard/vcard.rb', line 124 def encode #:nodoc: parts = @@adr_parts.map do |part| instance_variable_get(part) end value = ::Vcard.encode_text_list(parts, ";") params = [ @location, @delivery, @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( "ADR", value, paramshash) end |