Class: NicInfo::JCard

Inherits:
Object
  • Object
show all
Defined in:
lib/nicinfo/entity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJCard

Returns a new instance of JCard.



115
116
117
118
119
120
121
122
123
124
# File 'lib/nicinfo/entity.rb', line 115

def initialize
  @fns = Array.new
  @names = Array.new
  @phones = Array.new
  @emails = Array.new
  @adrs = Array.new
  @titles = Array.new
  @roles = Array.new
  @orgs = Array.new
end

Instance Attribute Details

#adrsObject

Returns the value of attribute adrs.



113
114
115
# File 'lib/nicinfo/entity.rb', line 113

def adrs
  @adrs
end

#emailsObject

Returns the value of attribute emails.



113
114
115
# File 'lib/nicinfo/entity.rb', line 113

def emails
  @emails
end

#fnsObject

Returns the value of attribute fns.



113
114
115
# File 'lib/nicinfo/entity.rb', line 113

def fns
  @fns
end

#kindObject

Returns the value of attribute kind.



113
114
115
# File 'lib/nicinfo/entity.rb', line 113

def kind
  @kind
end

#namesObject

Returns the value of attribute names.



113
114
115
# File 'lib/nicinfo/entity.rb', line 113

def names
  @names
end

#orgsObject

Returns the value of attribute orgs.



113
114
115
# File 'lib/nicinfo/entity.rb', line 113

def orgs
  @orgs
end

#phonesObject

Returns the value of attribute phones.



113
114
115
# File 'lib/nicinfo/entity.rb', line 113

def phones
  @phones
end

#rolesObject

Returns the value of attribute roles.



113
114
115
# File 'lib/nicinfo/entity.rb', line 113

def roles
  @roles
end

#titlesObject

Returns the value of attribute titles.



113
114
115
# File 'lib/nicinfo/entity.rb', line 113

def titles
  @titles
end

Instance Method Details

#get_vcard(entity) ⇒ Object



126
127
128
# File 'lib/nicinfo/entity.rb', line 126

def get_vcard entity
  return entity[ "vcardArray" ]
end

#process(entity) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/nicinfo/entity.rb', line 130

def process entity
  if ( vcard = get_vcard( entity ) ) != nil
    vcardElements = vcard[ 1 ]
    vcardElements.each do |element|
      if element[ 0 ] == "fn"
        @fns << element[ 3 ]
      end
      if element[ 0 ] == "n"
        name = ""
        if element[ 3 ][ -1 ].instance_of? Array
          name << element[ 3 ][ -1 ].join( ' ' )
        end
        name << ' ' if name[-1] != ' '
        name << element[ 3 ][ 1 ]
        if element[ 3 ][ 2 ] && !element[ 3 ][ 2 ].empty?
          name << " " << element[ 3 ][ 2 ]
        end
        if element[ 3 ][ 3 ] && !element[ 3 ][ 3 ].empty?
          name << " " << element[ 3 ][ 3 ]
        end
        name << " " << element[ 3 ][ 0 ]
        if element[ 3 ][ -2 ].instance_of? Array
          name << " " << element[ 3 ][ -2 ].join( ' ' )
        end
        @names << name
      end
      if element[ 0 ] == "tel"
        tel = Tel.new
        if (type = element[ 1 ][ "type" ]) != nil
          tel.type << type if type.instance_of? String
          tel.type = type if type.instance_of? Array
        end
        if (str = element[ 3 ] ).start_with?( "tel:" )
          tel.number=str[ /^tel\:([^;]*)/,1 ]
          tel.ext=str[ /[^;]*ext=(.*)/,1 ]
        else
          tel.number=str
        end
        @phones << tel
      end
      if element[ 0 ] == "email"
        email = Email.new
        if (type = element[ 1 ][ "type" ]) != nil
          email.type << type if type.instance_of? String
          email.type = type if type.instance_of? Array
        end
        email.addr=element[ 3 ]
        @emails << email
      end
      if element[ 0 ] == "adr"
        adr = Adr.new
        if (type = element[ 1 ][ "type" ]) != nil
          adr.type << type if type.instance_of? String
          adr.type = type if type.instance_of? Array
        end
        if (label = element[ 1 ][ "label" ]) != nil
          adr.label = label.split( "\n" )
        else
          adr.pobox=element[ 3 ][ 0 ]
          adr.extended=element[ 3 ][ 1 ]
          adr.street=element[ 3 ][ 2 ]
          adr.locality=element[ 3 ][ 3 ]
          adr.region=element[ 3 ][ 4 ]
          adr.postal=element[ 3 ][ 5 ]
          adr.country=element[ 3 ][ 6 ]
          adr.structured=true
        end
        @adrs << adr
      end
      if element[ 0 ] == "kind"
        @kind = element[ 3 ]
      end
      if element[ 0 ] == "title"
        @titles << element[ 3 ]
      end
      if element[ 0 ] == "role"
        @roles << element[ 3 ]
      end
      if element[ 0 ] == "org"
        org = Org.new
        if (type = element[ 1 ][ "type" ]) != nil
          org.type << type if type.instance_of? String
          org.type = type if type.instance_of? Array
        end
        names = element[ 3 ]
        org.names << names if names.instance_of? String
        org.names = org.names + names if names.instance_of? Array
        @orgs << org
      end
    end
  end
  return self
end