Class: Vpim::Vcard::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/vpim/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?



122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/vpim/vcard.rb', line 122

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)



93
94
95
# File 'lib/vpim/vcard.rb', line 93

def country
  @country
end

#deliveryObject

postal, parcel, dom (domestic), intl (international) (Array of String): delivery type of this address



100
101
102
# File 'lib/vpim/vcard.rb', line 100

def delivery
  @delivery
end

#extendedObject

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



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

def extended
  @extended
end

#localityObject

usually the city (String)



87
88
89
# File 'lib/vpim/vcard.rb', line 87

def locality
  @locality
end

#locationObject

home, work (Array of String): the location referred to by the address



95
96
97
# File 'lib/vpim/vcard.rb', line 95

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.



104
105
106
# File 'lib/vpim/vcard.rb', line 104

def nonstandard
  @nonstandard
end

#poboxObject

post office box (String)



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

def pobox
  @pobox
end

#postalcodeObject

postal code (String)



91
92
93
# File 'lib/vpim/vcard.rb', line 91

def postalcode
  @postalcode
end

#preferredObject

true, false (boolean): where this is the preferred address (for this location)



97
98
99
# File 'lib/vpim/vcard.rb', line 97

def preferred
  @preferred
end

#regionObject

usually the province or state (String)



89
90
91
# File 'lib/vpim/vcard.rb', line 89

def region
  @region
end

#streetObject

street address (String)



85
86
87
# File 'lib/vpim/vcard.rb', line 85

def street
  @street
end

Class Method Details

.decode(card, field) ⇒ Object

:nodoc:



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/vpim/vcard.rb', line 153

def Address.decode(card, field) #:nodoc:
  adr = new

  parts = Vpim.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:



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/vpim/vcard.rb', line 135

def encode #:nodoc:
  parts = @@adr_parts.map do |part|
    instance_variable_get(part)
  end

  value = Vpim.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

  Vpim::DirectoryInfo::Field.create( 'ADR', value, paramshash)
end