contacts_txt 0.3.1 → 0.4.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/contacts_txt.rb +86 -85
- data.tar.gz.sig +0 -0
- metadata +30 -30
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf478e02d22813b059b002369a94120ffa7db0c98e7ee02f7eb5a7604f000e36
|
4
|
+
data.tar.gz: 0e220217e01429b1b35c059df1e8459100ee4003a618c8634dcafd09ca30baeb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71e031cd9bef37e5d93c634832d2ba450a17605cbbf5c088898a73b1678cb0c477bfce0eddfa60604c784805b3126bd8e1305ebc494e78927aea4024339e0752
|
7
|
+
data.tar.gz: 1d0686e575cd7242676541d2ad093a113c5ffd95666f56450d1139376d4d399ecd6c67e7b547f9118e02cc4f7e42620e93dd2752b550f445c43cab008d216a0c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/contacts_txt.rb
CHANGED
@@ -3,26 +3,27 @@
|
|
3
3
|
# file: contacts_txt.rb
|
4
4
|
|
5
5
|
require 'dynarex'
|
6
|
+
require 'rxfreadwrite'
|
6
7
|
|
7
8
|
|
8
9
|
class ContactsTxt
|
9
|
-
include
|
10
|
+
include RXFReadWriteModule
|
10
11
|
|
11
12
|
attr_reader :to_s
|
12
|
-
|
13
|
-
def initialize(src=nil, fields: %w(role organisation mobile
|
14
|
-
sms email dob tags address notes note mobile2 ),
|
13
|
+
|
14
|
+
def initialize(src=nil, fields: %w(role organisation mobile
|
15
|
+
sms email dob tags address notes note mobile2 ),
|
15
16
|
username: nil, password: nil, debug: false)
|
16
|
-
|
17
|
+
|
17
18
|
@debug = debug
|
18
19
|
@fields = %w(fullname firstname lastname tel) | fields
|
19
20
|
|
20
21
|
txt, type = if src then
|
21
|
-
|
22
|
+
RXFReader.read(src, username: username, password: password)
|
22
23
|
else
|
23
24
|
['', :unknown]
|
24
25
|
end
|
25
|
-
|
26
|
+
|
26
27
|
case type
|
27
28
|
when :file
|
28
29
|
@path, @filename = File.dirname(src), File.basename(src)
|
@@ -33,100 +34,100 @@ class ContactsTxt
|
|
33
34
|
when :unknown
|
34
35
|
@path, @filename = '.', 'contacts.txt'
|
35
36
|
end
|
36
|
-
|
37
|
+
|
37
38
|
@dx = txt.lines.length > 1 ? import_to_dx(txt) : new_dx()
|
38
39
|
|
39
40
|
end
|
40
|
-
|
41
|
+
|
41
42
|
def all()
|
42
43
|
@dx.all
|
43
44
|
end
|
44
|
-
|
45
|
+
|
45
46
|
def dx()
|
46
47
|
@dx
|
47
48
|
end
|
48
|
-
|
49
|
+
|
49
50
|
def find_by_id(id)
|
50
|
-
|
51
|
+
|
51
52
|
@dx.find_by_id id
|
52
|
-
|
53
|
+
|
53
54
|
end
|
54
|
-
|
55
|
+
|
55
56
|
def find_by_mobile(raw_number, countrycode='44')
|
56
57
|
|
57
58
|
number = Regexp.new raw_number.sub(/^(?:0|#{countrycode})/,'').gsub(/[ -]*/,'')
|
58
|
-
|
59
|
-
@dx.all.find {|x| x.mobile.gsub(/[ -]*/,'') =~ number }
|
60
59
|
|
61
|
-
|
62
|
-
|
60
|
+
@dx.all.find {|x| x.mobile.gsub(/[ -]*/,'') =~ number }
|
61
|
+
|
62
|
+
end
|
63
|
+
|
63
64
|
def find_by_name(s)
|
64
65
|
|
65
66
|
# Appending a hashtag to the name can help with finding the specific record
|
66
|
-
# e.g. 'Peter#plumber' or 'Peter #plumber'
|
67
|
-
|
67
|
+
# e.g. 'Peter#plumber' or 'Peter #plumber'
|
68
|
+
|
68
69
|
raw_name, tag = s.split('#',2).map(&:strip)
|
69
|
-
|
70
|
+
|
70
71
|
name = Regexp.new "\b#{raw_name}\b|#{raw_name}", Regexp::IGNORECASE
|
71
72
|
puts 'name: ' + name.inspect if @debug
|
72
|
-
|
73
|
-
a = @dx.all.select do |x|
|
73
|
+
|
74
|
+
a = @dx.all.select do |x|
|
74
75
|
x.fullname =~ name or x.firstname =~ name or x.lastname =~ name
|
75
76
|
end
|
76
|
-
|
77
|
+
|
77
78
|
if tag then
|
78
|
-
a.find {|x| x.tags.split.map(&:downcase).include? tag.downcase }
|
79
|
+
a.find {|x| x.tags.split.map(&:downcase).include? tag.downcase }
|
79
80
|
else
|
80
81
|
a
|
81
82
|
end
|
82
83
|
|
83
|
-
end
|
84
|
-
|
84
|
+
end
|
85
|
+
|
85
86
|
def find_by_sms(raw_number, countrycode='44')
|
86
87
|
|
87
88
|
number = Regexp.new raw_number\
|
88
89
|
.sub(/^(?:0|#{countrycode})/,'').gsub(/[ -]*/,'')
|
89
|
-
|
90
|
+
|
90
91
|
@dx.all.find {|x| x.sms.gsub(/[ -]*/,'') =~ number \
|
91
|
-
or x.mobile.gsub(/[ -]*/,'') =~ number }
|
92
|
+
or x.mobile.gsub(/[ -]*/,'') =~ number }
|
92
93
|
|
93
|
-
end
|
94
|
-
|
95
|
-
# find using the tel, mobile, or mobile2 fields
|
94
|
+
end
|
95
|
+
|
96
|
+
# find using the tel, mobile, or mobile2 fields
|
96
97
|
#
|
97
98
|
def find_by_telno(raw_number)
|
98
99
|
|
99
100
|
number = Regexp.new raw_number.gsub(/[ -]*/,'')
|
100
|
-
|
101
|
+
|
101
102
|
@dx.all.find do |x|
|
102
|
-
|
103
|
+
|
103
104
|
numbers = %i(tel mobile mobile2).map do |y|
|
104
105
|
x.method(y).call.gsub(/[ -]*/,'') if x.respond_to? y
|
105
106
|
end
|
106
|
-
|
107
|
+
|
107
108
|
puts 'numbers: ' + numbers.inspect if @debug
|
108
109
|
numbers.grep(number).any?
|
109
110
|
end
|
110
111
|
|
111
|
-
end
|
112
|
+
end
|
112
113
|
|
113
114
|
# returns a Dynarex object
|
114
|
-
#
|
115
|
+
#
|
115
116
|
def email_list()
|
116
117
|
@dx.filter {|x| x.email.length > 0}
|
117
118
|
end
|
118
|
-
|
119
|
+
|
119
120
|
def list_names()
|
120
|
-
|
121
|
+
|
121
122
|
@dx.all.inject([]) do |r, x|
|
122
123
|
x.fullname.length >= 1 ? r << x.fullname : r
|
123
124
|
end
|
124
125
|
|
125
126
|
end
|
126
|
-
|
127
|
+
|
127
128
|
def mobile_list()
|
128
129
|
@dx.filter {|x| x.mobile.length > 0}
|
129
|
-
end
|
130
|
+
end
|
130
131
|
|
131
132
|
def multi_tel_index()
|
132
133
|
|
@@ -137,7 +138,7 @@ class ContactsTxt
|
|
137
138
|
end
|
138
139
|
next unless tel
|
139
140
|
"%s %s" % [x.fullname, x.method(tel).call]
|
140
|
-
end.compact
|
141
|
+
end.compact
|
141
142
|
|
142
143
|
|
143
144
|
# group by first name
|
@@ -152,8 +153,8 @@ class ContactsTxt
|
|
152
153
|
c.each do |k, v|
|
153
154
|
|
154
155
|
puts "k: %s v: %s" % [k, v]
|
155
|
-
v.concat(r2[k]) if r2[k]
|
156
|
-
|
156
|
+
v.concat(r2[k]) if r2[k]
|
157
|
+
|
157
158
|
end
|
158
159
|
|
159
160
|
h = c.sort.each {|k,v| v.uniq!}.to_h
|
@@ -170,9 +171,9 @@ class ContactsTxt
|
|
170
171
|
out << "\n" + (name.length >= 29 ? name[0..26] + '...' : name)
|
171
172
|
tel = (' ' + ' ' * (26 - phone.length)) + 't: ' + phone
|
172
173
|
out << tel + "\n"
|
173
|
-
out << ('-' * 30)
|
174
|
+
out << ('-' * 30)
|
174
175
|
|
175
|
-
end
|
176
|
+
end
|
176
177
|
|
177
178
|
end
|
178
179
|
|
@@ -181,17 +182,17 @@ class ContactsTxt
|
|
181
182
|
end
|
182
183
|
|
183
184
|
def save(filename=@filename)
|
184
|
-
|
185
|
+
|
185
186
|
s = dx_to_s(@dx)
|
186
187
|
FileX.write File.join(@path, filename), s
|
187
188
|
@dx.save File.join(@path, filename.sub(/\.txt$/,'.xml'))
|
188
|
-
|
189
|
+
|
189
190
|
end
|
190
|
-
|
191
|
+
|
191
192
|
def to_dx()
|
192
193
|
@dx
|
193
194
|
end
|
194
|
-
|
195
|
+
|
195
196
|
def to_s()
|
196
197
|
dx_to_s @dx
|
197
198
|
end
|
@@ -199,9 +200,9 @@ class ContactsTxt
|
|
199
200
|
private
|
200
201
|
|
201
202
|
def dx_to_s(dx)
|
202
|
-
|
203
|
+
|
203
204
|
rows = dx.all.map do |row|
|
204
|
-
|
205
|
+
|
205
206
|
h = row.to_h
|
206
207
|
|
207
208
|
fullname = h.delete :fullname
|
@@ -211,11 +212,11 @@ class ContactsTxt
|
|
211
212
|
|
212
213
|
([fullname] + a.map {|x| x.join(': ') }).join("\n")
|
213
214
|
end
|
214
|
-
|
215
|
+
|
215
216
|
"<?contacts fields='%s'?>\n\n%s" % [@fields, rows.join("\n\n")]
|
216
|
-
|
217
|
+
|
217
218
|
end
|
218
|
-
|
219
|
+
|
219
220
|
def import_to_dx(raw_s)
|
220
221
|
|
221
222
|
s = if raw_s =~ /<?contacts / then
|
@@ -227,50 +228,50 @@ class ContactsTxt
|
|
227
228
|
found = s2[/(?<=#{keyword}=['"])[^'"]+/]
|
228
229
|
found ? r.merge(keyword.to_sym => found) : r
|
229
230
|
end
|
230
|
-
|
231
|
+
|
231
232
|
h = {
|
232
|
-
fields: @fields.join(', '),
|
233
|
-
}.merge attributes
|
233
|
+
fields: @fields.join(', '),
|
234
|
+
}.merge attributes
|
234
235
|
|
235
|
-
@fields = h[:fields].split(/ *, */)
|
236
|
+
@fields = h[:fields].split(/ *, */)
|
236
237
|
|
237
238
|
if h[:root] then
|
238
|
-
"\n\n" + h[:root] + "\n" +
|
239
|
+
"\n\n" + h[:root] + "\n" +
|
239
240
|
raw_contacts.strip.lines.map {|line| ' ' + line}.join
|
240
241
|
else
|
241
242
|
raw_contacts
|
242
243
|
end
|
243
|
-
|
244
|
+
|
244
245
|
else
|
245
|
-
|
246
|
+
|
246
247
|
raw_s.lstrip.lines[2..-1].join.strip
|
247
248
|
|
248
249
|
end
|
249
250
|
|
250
251
|
new_dx().import "--+\n" + s.split(/\s+(?=^[\w\s\(\)]+$)/)\
|
251
|
-
.map {|x| 'fullname: ' + x }.join("\n")
|
252
|
-
|
252
|
+
.map {|x| 'fullname: ' + x }.join("\n")
|
253
|
+
|
253
254
|
end
|
254
|
-
|
255
|
+
|
255
256
|
def new_dx()
|
256
|
-
|
257
|
+
|
257
258
|
Dynarex.new "contacts/contact(#{@fields.join ', '})"
|
258
|
-
|
259
|
+
|
259
260
|
end
|
260
261
|
|
261
262
|
end
|
262
263
|
|
263
264
|
class ContactsTxtAgent < ContactsTxt
|
264
|
-
|
265
|
+
|
265
266
|
def find_mobile_by_name(s)
|
266
|
-
|
267
|
+
|
267
268
|
result = find_by_name(s)
|
268
269
|
|
269
|
-
r = validate(result)
|
270
|
-
|
270
|
+
r = validate(result)
|
271
|
+
|
271
272
|
numbers = [r.sms.empty? ? r.mobile : r.sms, r.mobile].uniq\
|
272
273
|
.map {|x| x.sub(/\([^\)]+\)/,'').strip}
|
273
|
-
|
274
|
+
|
274
275
|
h = {}
|
275
276
|
h[:msg] = if numbers.length > 1 then
|
276
277
|
"The SMS number for %s is %s and the mobile number is %s" % \
|
@@ -285,30 +286,30 @@ class ContactsTxtAgent < ContactsTxt
|
|
285
286
|
end
|
286
287
|
|
287
288
|
h[:tags] = r.tags.to_s
|
288
|
-
h
|
289
|
+
h
|
289
290
|
end
|
290
|
-
|
291
|
+
|
291
292
|
def find_tel_by_name(s)
|
292
|
-
|
293
|
+
|
293
294
|
result = find_by_name(s)
|
294
|
-
r = validate(result)
|
295
|
-
|
295
|
+
r = validate(result)
|
296
|
+
|
296
297
|
h = {}
|
297
|
-
|
298
|
+
|
298
299
|
if r.tel.empty? then
|
299
300
|
return find_mobile_by_name(s)
|
300
301
|
else
|
301
302
|
h[:msg] = "The telephone number for %s is %s" % [r.fullname, r.tel]
|
302
303
|
end
|
303
|
-
|
304
|
+
|
304
305
|
h[:tags] = r.tags.to_s
|
305
|
-
h
|
306
|
+
h
|
306
307
|
end
|
307
308
|
|
308
309
|
private
|
309
|
-
|
310
|
+
|
310
311
|
def validate(result)
|
311
|
-
|
312
|
+
|
312
313
|
case result.class.to_s
|
313
314
|
when 'RecordX'
|
314
315
|
result
|
@@ -316,8 +317,8 @@ class ContactsTxtAgent < ContactsTxt
|
|
316
317
|
result.first
|
317
318
|
when 'NilClass'
|
318
319
|
return "I couldn't find that name."
|
319
|
-
end
|
320
|
-
|
320
|
+
end
|
321
|
+
|
321
322
|
end
|
322
|
-
|
323
|
+
|
323
324
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contacts_txt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -11,31 +11,31 @@ cert_chain:
|
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
13
|
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjIwMjIzMTk0ODIwWhcN
|
15
|
+
MjMwMjIzMTk0ODIwWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDlecEA
|
17
|
+
1V+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BrHmj9zvfFWXnnRoFa06JIHm2DmOB
|
31
|
+
41DwQiiLflNj4iYbLzNQSI5X0iRu3H8zcAp45HJNF2LBrY32b8U+4Uf1w9QOJ4Io
|
32
|
+
bXdjMDxNnHEj2+V2yaq4J8v0o/xEE0Qv2TEeXyiv2fvIRz5VsS3ayYv+rHVmxGuo
|
33
|
+
VuXOnyLlTUjeB0IakaSYdBFWW3uno+fds/mIBL9VtmZzPJ4UhirVs0t4GvftJ2oT
|
34
|
+
weBCjBPmFwYPtn66vFgOaUHK421yIA2FC+AQO/pOOSgngHz0pm08NMpcTeTaufKu
|
35
|
+
x9gWyaB0gatLOaqUuwj8jCICpzNLo20JZQyEav2hZDxdB1EQjxq9jZrMaxwW3lF/
|
36
|
+
zHoZFKaw47O+Nd14HCqMVZUt
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2022-02-23 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: dynarex
|
@@ -43,22 +43,22 @@ dependencies:
|
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '1.
|
46
|
+
version: '1.9'
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 1.
|
49
|
+
version: 1.9.6
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
54
|
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: '1.
|
56
|
+
version: '1.9'
|
57
57
|
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: 1.
|
59
|
+
version: 1.9.6
|
60
60
|
description:
|
61
|
-
email:
|
61
|
+
email: digital.robertson@gmail.com
|
62
62
|
executables: []
|
63
63
|
extensions: []
|
64
64
|
extra_rdoc_files: []
|
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
86
|
+
rubygems_version: 3.2.22
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: Reads a contacts.txt file
|
metadata.gz.sig
CHANGED
Binary file
|