Class: Vcard::Vcard::Address

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAddress

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

#countryObject

country name (String)



83
84
85
# File 'lib/vcard/vcard.rb', line 83

def country
  @country
end

#deliveryObject

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

#extendedObject

seldom used, its not clear what it is for (String)



73
74
75
# File 'lib/vcard/vcard.rb', line 73

def extended
  @extended
end

#localityObject

usually the city (String)



77
78
79
# File 'lib/vcard/vcard.rb', line 77

def locality
  @locality
end

#locationObject

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

#nonstandardObject (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

#poboxObject

post office box (String)



71
72
73
# File 'lib/vcard/vcard.rb', line 71

def pobox
  @pobox
end

#postalcodeObject

postal code (String)



81
82
83
# File 'lib/vcard/vcard.rb', line 81

def postalcode
  @postalcode
end

#preferredObject

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

#regionObject

usually the province or state (String)



79
80
81
# File 'lib/vcard/vcard.rb', line 79

def region
  @region
end

#streetObject

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

#encodeObject

: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