simplevpim 0.2.0 → 0.5.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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/simplevpim.rb +208 -18
- metadata +37 -34
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 837294bf422fd83d5713759e1983df1d04b6843557790a89f041c1aea5e81469
|
4
|
+
data.tar.gz: ce99d263776326cdac99f6831b1c8ce4bcc7f54d25d828175c215bfd9ba263ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b412cde4385b238ad9073e93d8be7346f2bd600b9d44d90297250f34ba670209fefbb97915dc8b7dfa55114a0c47e95213f0355494c11eb82409994be6191900
|
7
|
+
data.tar.gz: 97ef6fedf467824363b642147202d6cacaea03700d0492bd15969483ebf690891480da634cf8eea859676d9d6252bb7d9d8b2456bd4aa9ea4c6d800c7103ea97
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/simplevpim.rb
CHANGED
@@ -2,28 +2,48 @@
|
|
2
2
|
|
3
3
|
# file: simplevpim.rb
|
4
4
|
|
5
|
+
require 'hlt'
|
6
|
+
require 'nokogiri'
|
5
7
|
require 'vpim/vcard'
|
6
8
|
require 'rexle-builder'
|
7
|
-
require '
|
9
|
+
require 'kvx'
|
10
|
+
require 'unichron'
|
8
11
|
|
9
12
|
|
10
13
|
class SimpleVpim
|
11
14
|
|
12
|
-
attr_reader :to_vcard, :to_xml
|
15
|
+
attr_reader :to_vcard, :to_vevent, :to_xml
|
13
16
|
|
14
17
|
def initialize(s)
|
15
18
|
|
16
|
-
|
19
|
+
kvx = Kvx.new(s)
|
20
|
+
@h = kvx.to_h
|
17
21
|
|
18
|
-
if h[:name] then
|
19
|
-
|
20
|
-
@
|
22
|
+
if s.lstrip =~ /# vcard/ and @h[:name] then
|
23
|
+
|
24
|
+
@to_vcard = make_vcard @h
|
25
|
+
@to_xml = vcard_xml @h
|
26
|
+
|
27
|
+
elsif @h[:title] or @h[:summary]
|
28
|
+
|
29
|
+
@to_vevent = make_vevent @h
|
30
|
+
@to_xml = vevent_xml kvx.to_xml
|
31
|
+
|
21
32
|
end
|
22
33
|
|
23
34
|
end
|
24
35
|
|
25
36
|
alias to_vcf to_vcard
|
26
37
|
|
38
|
+
def to_hcard(layout=nil)
|
39
|
+
make_hcard layout, @h
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_xcard()
|
43
|
+
make_xcard @to_xml
|
44
|
+
end
|
45
|
+
|
46
|
+
|
27
47
|
private
|
28
48
|
|
29
49
|
def extract_names(name)
|
@@ -32,20 +52,20 @@ class SimpleVpim
|
|
32
52
|
|
33
53
|
if a.length == 2 then
|
34
54
|
|
35
|
-
firstname,
|
55
|
+
firstname, surname = a[0],nil,a[-1], name
|
36
56
|
|
37
57
|
elsif a[0][/^Mrs?|Ms|Miss|Dr/] then
|
38
58
|
|
39
59
|
prefix = a.shift
|
40
60
|
|
41
61
|
if a.length == 2 then
|
42
|
-
firstname,
|
62
|
+
firstname, surname = a[0],nil,a[-1], name
|
43
63
|
else
|
44
|
-
[*a, a.join
|
64
|
+
[*a, a.join(' ')]
|
45
65
|
end
|
46
66
|
|
47
67
|
else
|
48
|
-
[*a, a.join
|
68
|
+
[*a, a.join(' ')]
|
49
69
|
end
|
50
70
|
end
|
51
71
|
|
@@ -63,12 +83,12 @@ class SimpleVpim
|
|
63
83
|
prefix = h[:prefix]
|
64
84
|
suffix = h[:suffix]
|
65
85
|
|
66
|
-
firstname, middlename,
|
86
|
+
firstname, middlename, surname, fullname = extract_names(h[:name])
|
67
87
|
|
68
88
|
maker.add_name do |name|
|
69
89
|
name.prefix = prefix if prefix
|
70
90
|
name.given = firstname
|
71
|
-
name.family =
|
91
|
+
name.family = surname
|
72
92
|
name.suffix = suffix if suffix
|
73
93
|
name.fullname = fullname if fullname
|
74
94
|
end
|
@@ -146,12 +166,174 @@ class SimpleVpim
|
|
146
166
|
end
|
147
167
|
end
|
148
168
|
|
169
|
+
def make_vevent(h)
|
170
|
+
|
171
|
+
dstart, dend = %i(start end).map do |x|
|
172
|
+
Unichron.new(h[x]).to_date.strftime("%Y%m%d")
|
173
|
+
end
|
174
|
+
|
175
|
+
s = "BEGIN:VEVENT
|
176
|
+
SUMMARY:#{h[:title] || h[:summary]}
|
177
|
+
DTSTART;VALUE=DATE:#{dstart}
|
178
|
+
DTEND;VALUE=DATE:#{dend}
|
179
|
+
"
|
180
|
+
|
181
|
+
s += 'LOCATION:' + h[:location] + "\n" if h[:location]
|
182
|
+
s += 'DESCRIPTION:' + h[:description] + "\n" if h[:description]
|
183
|
+
s += 'END:VEVENT'
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
def make_hcard(raw_s, h)
|
188
|
+
|
189
|
+
raw_s ||= %q(
|
190
|
+
# hcard
|
191
|
+
|
192
|
+
img.photo
|
193
|
+
h1.fn
|
194
|
+
.email
|
195
|
+
.n
|
196
|
+
|
197
|
+
home:
|
198
|
+
.label
|
199
|
+
.adr
|
200
|
+
.tel
|
201
|
+
|
202
|
+
work:
|
203
|
+
.label
|
204
|
+
.adr
|
205
|
+
.tel
|
206
|
+
)
|
207
|
+
|
208
|
+
s = raw_s.split(/\n(?=\w+:?)/).inject('') do |r, x|
|
209
|
+
|
210
|
+
x.sub!(/^\s*#\s+.*/,'') # ignore comments
|
211
|
+
|
212
|
+
lines = x.lines
|
213
|
+
type = lines[0][/^(\w+):/,1]
|
214
|
+
|
215
|
+
if type then
|
216
|
+
|
217
|
+
lines.shift
|
218
|
+
|
219
|
+
r << lines.map do |line|
|
220
|
+
|
221
|
+
if line[/\s*\.\w+/] then
|
222
|
+
indent = line[/^ +/].to_s
|
223
|
+
"%s%sspan.type %s" % [line.sub(/^ {2}/,''), indent, type]
|
224
|
+
else
|
225
|
+
line
|
226
|
+
end
|
227
|
+
|
228
|
+
end.join("\n") + "\n"
|
229
|
+
|
230
|
+
else
|
231
|
+
|
232
|
+
r << x + "\n"
|
233
|
+
end
|
234
|
+
|
235
|
+
r
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
html_string = Hlt.new(s).to_html
|
240
|
+
html_template = <<EOF
|
241
|
+
<html>
|
242
|
+
<head>
|
243
|
+
<link rel="profile" href="http://microformats.org/profile/hcard" />
|
244
|
+
</head>
|
245
|
+
<body>
|
246
|
+
<div class='vcard'>#{html_string}</div>
|
247
|
+
</body>
|
248
|
+
</html>
|
249
|
+
EOF
|
250
|
+
doc = Rexle.new(html_template)
|
251
|
+
|
252
|
+
def doc.set(selector, val=nil)
|
253
|
+
|
254
|
+
e = self.at_css selector
|
255
|
+
return unless e
|
256
|
+
block_given? ? yield(e) : e.text = val
|
257
|
+
|
258
|
+
end
|
259
|
+
|
260
|
+
firstname, middlename, surname, fullname = extract_names(h[:name])
|
261
|
+
doc.set '.fn', fullname
|
262
|
+
|
263
|
+
#-- name ---------
|
264
|
+
|
265
|
+
e = doc.at_css '.n'
|
266
|
+
e.text = 'First Name:'
|
267
|
+
fname = Rexle::Element.new('span')
|
268
|
+
fname.attributes[:class] = 'given-name'
|
269
|
+
fname.text = firstname
|
270
|
+
e.add_element fname
|
271
|
+
e.add_element Rexle::Element.new('br')
|
272
|
+
e.add_text 'Last Name:'
|
273
|
+
lname = Rexle::Element.new('span')
|
274
|
+
lname.attributes[:class] = 'family-name'
|
275
|
+
lname.text = surname
|
276
|
+
e.add_element lname
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
doc.at_css('.photo').delete unless h[:photo]
|
281
|
+
doc.css('.tel').each(&:delete) unless h[:tel]
|
282
|
+
doc.css('.adr').each(&:delete) unless h[:adr]
|
283
|
+
doc.css('.label').each(&:delete) unless h[:label]
|
284
|
+
|
285
|
+
if h[:email].is_a? String then
|
286
|
+
|
287
|
+
e = doc.at_css '.email'
|
288
|
+
e.text = 'Email:'
|
289
|
+
alink = Rexle::Element.new('a')
|
290
|
+
alink.attributes[:class] = 'value'
|
291
|
+
alink.attributes[:href] = 'mailto:' + h[:email]
|
292
|
+
alink.text = h[:email]
|
293
|
+
e.add_element alink
|
294
|
+
|
295
|
+
elsif h[:email].is_a? Hash then
|
296
|
+
|
297
|
+
node = doc.at_css('.email')
|
298
|
+
|
299
|
+
h[:email].reverse_each do |k,v|
|
300
|
+
e = node.clone
|
301
|
+
type = Rexle::Element.new('span')
|
302
|
+
type.attributes[:class] = 'type'
|
303
|
+
type.text = k.capitalize
|
304
|
+
e.add_element type
|
305
|
+
e.add_text ' Email:'
|
306
|
+
alink = Rexle::Element.new('a')
|
307
|
+
alink.attributes[:class] = 'value'
|
308
|
+
alink.attributes[:href] = 'mailto:' + v
|
309
|
+
alink.text = v
|
310
|
+
e.add_element alink
|
311
|
+
|
312
|
+
node.insert_after e
|
313
|
+
end
|
314
|
+
node.delete
|
315
|
+
|
316
|
+
end
|
317
|
+
|
318
|
+
doc.xml pretty: true, declaration: false
|
319
|
+
|
320
|
+
end
|
321
|
+
|
322
|
+
def make_xcard(xml)
|
323
|
+
#lib = File.dirname(__FILE__)
|
324
|
+
lib = 'http://a0.jamesrobertson.me.uk/rorb/r/ruby/simplevpim'
|
325
|
+
xsl = open(lib + '/xcard.xsl','UserAgent' => 'SimplevPim').read
|
326
|
+
doc = Nokogiri::XML(xml)
|
327
|
+
xslt = Nokogiri::XSLT(xsl)
|
328
|
+
xslt.transform(doc).to_s
|
329
|
+
end
|
330
|
+
|
149
331
|
def vcard_xml(h)
|
150
332
|
|
151
333
|
prefix = h[:prefix]
|
152
334
|
suffix = h[:suffix]
|
153
335
|
|
154
|
-
firstname, middlename,
|
336
|
+
firstname, middlename, surname, fullname = extract_names(h[:name])
|
155
337
|
|
156
338
|
xml = RexleBuilder.new
|
157
339
|
|
@@ -159,11 +341,11 @@ class SimpleVpim
|
|
159
341
|
|
160
342
|
xml.name do
|
161
343
|
|
162
|
-
xml.prefix
|
163
|
-
xml.given
|
164
|
-
xml.family
|
165
|
-
xml.suffix
|
166
|
-
xml.fullname
|
344
|
+
xml.prefix prefix if prefix
|
345
|
+
xml.given firstname
|
346
|
+
xml.family surname
|
347
|
+
xml.suffix suffix if suffix
|
348
|
+
xml.fullname fullname if fullname
|
167
349
|
end
|
168
350
|
|
169
351
|
# -- email -----------------------------
|
@@ -242,5 +424,13 @@ class SimpleVpim
|
|
242
424
|
|
243
425
|
Rexle.new(a)
|
244
426
|
end
|
427
|
+
|
428
|
+
def vevent_xml(xml)
|
429
|
+
|
430
|
+
doc = Rexle.new(xml)
|
431
|
+
doc.root.name = 'vevent'
|
432
|
+
doc.root.xml
|
433
|
+
|
434
|
+
end
|
245
435
|
|
246
436
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,49 +10,53 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
13
|
+
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjEwNjIxMjI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rtbcfPpL6HnC3jDa7bVmsh79nEXbCzAAtAG5wckmOyFQvVTr
|
30
|
+
Zv0+gw5uwt3v2ac4xdwCRcte/8vZtd7malj2UL2YHjSG0Y9iVbMbIQoeMQFrUTLQ
|
31
|
+
SNdUvlE6jDatAHLajoOel0P4qV6i98pYRZVD+jH7mG1n5D2xyDnov8OoK7cAYPvB
|
32
|
+
hKS+vGsPMK6D70pa3cSiOF6kYE94pgFL2OdoxpEpaKQukTzZnfODDSUx/IPud4OP
|
33
|
+
nH2NGMAKFKRnV1ckoSFcvhYYzJGpYYGFlGGMrAPtzAW8NyHDOwwA/koYXY1oh9kB
|
34
|
+
iOeNjtxEJvb/5Qnz8M8K2CBXRfktT6ZghoJMc12q2bM3XE71RF3yJ/E250/Xp3+Z
|
35
|
+
dBpGyLXPFeCV5Z8rWY+S891OLL3UPvcmIiolU7aaNSwvXBGLesCCH6TrIdhw4q2z
|
36
|
+
pM4lNlA3G8w+xUHw/9AE8V6p
|
33
37
|
-----END CERTIFICATE-----
|
34
|
-
date:
|
38
|
+
date: 2021-06-21 00:00:00.000000000 Z
|
35
39
|
dependencies:
|
36
40
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
41
|
+
name: hlt
|
38
42
|
requirement: !ruby/object:Gem::Requirement
|
39
43
|
requirements:
|
40
44
|
- - "~>"
|
41
45
|
- !ruby/object:Gem::Version
|
42
|
-
version: '0.
|
46
|
+
version: '0.6'
|
43
47
|
- - ">="
|
44
48
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
49
|
+
version: 0.6.3
|
46
50
|
type: :runtime
|
47
51
|
prerelease: false
|
48
52
|
version_requirements: !ruby/object:Gem::Requirement
|
49
53
|
requirements:
|
50
54
|
- - "~>"
|
51
55
|
- !ruby/object:Gem::Version
|
52
|
-
version: '0.
|
56
|
+
version: '0.6'
|
53
57
|
- - ">="
|
54
58
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.
|
59
|
+
version: 0.6.3
|
56
60
|
- !ruby/object:Gem::Dependency
|
57
61
|
name: vpim
|
58
62
|
requirement: !ruby/object:Gem::Requirement
|
@@ -79,22 +83,22 @@ dependencies:
|
|
79
83
|
requirements:
|
80
84
|
- - "~>"
|
81
85
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0
|
86
|
+
version: '1.0'
|
83
87
|
- - ">="
|
84
88
|
- !ruby/object:Gem::Version
|
85
|
-
version: 0.
|
89
|
+
version: 1.0.3
|
86
90
|
type: :runtime
|
87
91
|
prerelease: false
|
88
92
|
version_requirements: !ruby/object:Gem::Requirement
|
89
93
|
requirements:
|
90
94
|
- - "~>"
|
91
95
|
- !ruby/object:Gem::Version
|
92
|
-
version: '0
|
96
|
+
version: '1.0'
|
93
97
|
- - ">="
|
94
98
|
- !ruby/object:Gem::Version
|
95
|
-
version: 0.
|
99
|
+
version: 1.0.3
|
96
100
|
description:
|
97
|
-
email:
|
101
|
+
email: digital.robertson@gmail.com
|
98
102
|
executables: []
|
99
103
|
extensions: []
|
100
104
|
extra_rdoc_files: []
|
@@ -119,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
123
|
- !ruby/object:Gem::Version
|
120
124
|
version: '0'
|
121
125
|
requirements: []
|
122
|
-
|
123
|
-
rubygems_version: 2.2.2
|
126
|
+
rubygems_version: 3.1.2
|
124
127
|
signing_key:
|
125
128
|
specification_version: 4
|
126
129
|
summary: A simple wrapper for the vPim gem
|
metadata.gz.sig
CHANGED
Binary file
|