simplevpim 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bcae27bf883093ae36bdf11dcb6e62efa04a0dde
4
- data.tar.gz: f5dda97fbdee5c8162a049609bbf28afdfe2661d
3
+ metadata.gz: 08ff15164eefc84e5d61257fe22ec8859d1f0655
4
+ data.tar.gz: 1b203ef978b22d2fdbbad12ed938778c15657e9b
5
5
  SHA512:
6
- metadata.gz: 7f3044e889a98a4fdd2e945a96b0d4e2dcbf1ad5c03ad09083d42f80b42b14dad24f64e8af95f38898e6e3d6128ff211be83bbd6186516b8c54d494c1c22a892
7
- data.tar.gz: 7e227671a4f8317eb9c375f17f88d29c335d9654726913d183be7a9fc7dc1c598b1217ef9ce114d675eaf27039f6090f124452e84b985081e1212488740dcc21
6
+ metadata.gz: d46e4ef92525db09907143557c0ea8770f49abe1dabfd95d6c8a7ac8edd8c4c8c6cd32af078e95bd14d7aeb964ca774a74cd69d83d2785447b7250448993f521
7
+ data.tar.gz: ae20137ecc6ca8af511f20cb415f62cc9315c58d821e6ffde1eb36cec9b9eab8d4379f1902d7eac666a6e6b2422e361a3365dec06b5dc3c5d63c149b9d39fd1d
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/simplevpim.rb CHANGED
@@ -3,12 +3,13 @@
3
3
  # file: simplevpim.rb
4
4
 
5
5
  require 'vpim/vcard'
6
+ require 'rexle-builder'
6
7
  require 'simple-config'
7
8
 
8
9
 
9
10
  class SimpleVpim
10
11
 
11
- attr_reader :to_vcard
12
+ attr_reader :to_vcard, :to_xml
12
13
 
13
14
  def initialize(s)
14
15
 
@@ -16,34 +17,39 @@ class SimpleVpim
16
17
 
17
18
  if h[:name] then
18
19
  @to_vcard = make_vcard h
20
+ @to_xml = vcard_xml h
19
21
  end
20
22
 
21
23
  end
22
24
 
23
25
  alias to_vcf to_vcard
26
+
27
+ private
28
+
29
+ def extract_names(name)
30
+
31
+ a = name.split
24
32
 
25
- def make_vcard(h)
26
-
27
- prefix = h[:prefix]
28
- suffix = h[:suffix]
29
- a = h[:name].split
30
-
31
33
  if a.length == 2 then
32
- firstname, lastname = a
34
+
35
+ firstname, lastname = a[0],nil,a[-1], name
36
+
33
37
  elsif a[0][/^Mrs?|Ms|Miss|Dr/] then
34
38
 
35
39
  prefix = a.shift
36
40
 
37
41
  if a.length == 2 then
38
- firstname, lastname = a
42
+ firstname, lastname = a[0],nil,a[-1], name
39
43
  else
40
- firstname, middlename, lastname = a
41
- fullname = a.join ' '
44
+ [*a, a.join, ' ']
42
45
  end
46
+
43
47
  else
44
- firstname, middlename, lastname = a
45
- fullname = a.join ' '
46
- end
48
+ [*a, a.join, ' ']
49
+ end
50
+ end
51
+
52
+ def make_vcard(h)
47
53
 
48
54
  card = Vpim::Vcard::Maker.make2 do |maker|
49
55
 
@@ -53,6 +59,11 @@ class SimpleVpim
53
59
  add_field field
54
60
 
55
61
  end
62
+
63
+ prefix = h[:prefix]
64
+ suffix = h[:suffix]
65
+
66
+ firstname, middlename, lastname, fullname = extract_names(h[:name])
56
67
 
57
68
  maker.add_name do |name|
58
69
  name.prefix = prefix if prefix
@@ -134,5 +145,102 @@ class SimpleVpim
134
145
 
135
146
  end
136
147
  end
148
+
149
+ def vcard_xml(h)
150
+
151
+ prefix = h[:prefix]
152
+ suffix = h[:suffix]
153
+
154
+ firstname, middlename, lastname, fullname = extract_names(h[:name])
155
+
156
+ xml = RexleBuilder.new
157
+
158
+ a = xml.vcard do
159
+
160
+ xml.name do
161
+
162
+ xml.prefix = prefix if prefix
163
+ xml.given = firstname
164
+ xml.family = lastname
165
+ xml.suffix = suffix if suffix
166
+ xml.fullname = fullname if fullname
167
+ end
168
+
169
+ # -- email -----------------------------
170
+
171
+ e = h[:email]
172
+
173
+ if e then
174
+
175
+ if e.is_a? String then
176
+
177
+ xml.email e
178
+
179
+ else
180
+ eh = h[:email][:home]
181
+ ew = h[:email][:work]
182
+ xml.email({location: 'work'}, ew) if ew
183
+ xml.email({location: 'home'}, eh) if eh
184
+ end
185
+ end
186
+
187
+ # -- urls ---------------------------------
188
+
189
+ h[:url] ||= h[:urls]
190
+
191
+ if h[:url] then
192
+
193
+ if h[:url].is_a? String then
194
+ xml.url h[:url]
195
+ else
196
+
197
+ # unfortunately vPim doesn't use a block with the add_url method
198
+ #maker.add_url (h[:url][:work]){|e| e.location = 'work'} if h[:url][:work]
199
+
200
+ h[:url][:items].each {|url| xml.url url }
201
+
202
+ end
203
+
204
+ end
205
+
206
+ # -- photos
207
+
208
+ xml.photo link: h[:photo] if h[:photo]
209
+
210
+ # -- telephone
211
+
212
+ tel = h[:tel]
213
+
214
+ if tel then
215
+
216
+ if tel.is_a? String then
217
+
218
+ xml.tel tel
219
+
220
+ else
221
+ th = h[:tel][:home]
222
+ tw = h[:tel][:work]
223
+ xml.tel({location: 'work'}, tw) if tw
224
+ xml.tel({location: 'home'}, th) if th
225
+ end
226
+ end
227
+
228
+ # -- categories ------------
229
+ xml.categories h[:categories].split(/\s*,\s*/) if h[:categories]
230
+
231
+ # -- source ------------
232
+ xml.source h[:source] if h[:source]
233
+
234
+ # -- Twitter ------------
235
+ xml.x_twitter h[:twitter] if h[:twitter]
236
+
237
+ # -- XMPP
238
+ xmpp = h[:jabber] || h[:xmpp]
239
+ xml.x_jabber({type: 'im'}, xmpp) if xmpp
240
+
241
+ end
242
+
243
+ Rexle.new(a)
244
+ end
137
245
 
138
246
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplevpim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  h7sjjIWKCtgcFF+5Gf5AtJf6C0PlDSh7mc8uoo2XSef/GV6YvwUrQbPtFakM7LDs
32
32
  a3f37q6Z/UCE6w==
33
33
  -----END CERTIFICATE-----
34
- date: 2014-11-06 00:00:00.000000000 Z
34
+ date: 2014-11-09 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: simple-config
@@ -73,6 +73,26 @@ dependencies:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: 13.11.11
76
+ - !ruby/object:Gem::Dependency
77
+ name: rexle-builder
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.1'
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 0.1.10
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - "~>"
91
+ - !ruby/object:Gem::Version
92
+ version: '0.1'
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 0.1.10
76
96
  description:
77
97
  email: james@r0bertson.co.uk
78
98
  executables: []
metadata.gz.sig CHANGED
Binary file