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?
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/vcard/vcard.rb', line 112 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)
83 84 85 |
# File 'lib/vcard/vcard.rb', line 83 def country @country end |
#delivery ⇒ Object
postal, parcel, dom (domestic), intl (international) (Array of String): delivery type of this address
90 91 92 |
# File 'lib/vcard/vcard.rb', line 90 def delivery @delivery end |
#extended ⇒ Object
seldom used, its not clear what it is for (String)
73 74 75 |
# File 'lib/vcard/vcard.rb', line 73 def extended @extended end |
#locality ⇒ Object
usually the city (String)
77 78 79 |
# File 'lib/vcard/vcard.rb', line 77 def locality @locality end |
#location ⇒ Object
home, work (Array of String): the location referred to by the address
85 86 87 |
# File 'lib/vcard/vcard.rb', line 85 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.
94 95 96 |
# File 'lib/vcard/vcard.rb', line 94 def nonstandard @nonstandard end |
#pobox ⇒ Object
post office box (String)
71 72 73 |
# File 'lib/vcard/vcard.rb', line 71 def pobox @pobox end |
#postalcode ⇒ Object
postal code (String)
81 82 83 |
# File 'lib/vcard/vcard.rb', line 81 def postalcode @postalcode end |
#preferred ⇒ Object
true, false (boolean): where this is the preferred address (for this location)
87 88 89 |
# File 'lib/vcard/vcard.rb', line 87 def preferred @preferred end |
#region ⇒ Object
usually the province or state (String)
79 80 81 |
# File 'lib/vcard/vcard.rb', line 79 def region @region end |
#street ⇒ Object
street address (String)
75 76 77 |
# File 'lib/vcard/vcard.rb', line 75 def street @street end |
Class Method Details
.decode(card, field) ⇒ Object
:nodoc:
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 175 |
# File 'lib/vcard/vcard.rb', line 143 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:
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/vcard/vcard.rb', line 125 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 |