contacts_txt 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd0833b7b56a5639600af7e814f3c4af60ad9f7165c794f249610584489d55ff
4
- data.tar.gz: 8b072876b747432512bea5baa71f78a33d9121c7f18ba02ab04c0c555fb59b58
3
+ metadata.gz: 9abd4607e4765b8edaa26fa9880f4152f5187868ce84e11308fcc6b3918c734d
4
+ data.tar.gz: 39609f542c37597a33cb42723488431cbd19cfec2c873919d69581d5f5c9d2c1
5
5
  SHA512:
6
- metadata.gz: 3d49e37178cf48065ced603ac1ff78b482a09b57b3ca8b27193cd7124727ce874bd62fe8914c5531d09ac4ea58b15b6e7bdd42374e8251105ec3fe704cff8682
7
- data.tar.gz: b701993637e978e8a7eb44c63c4e44c8e1c19a42e9582dd6922906ea30cda1a41e219c29e6f5ae536a7fc6a1da18c6d953fccde546461902adaeaaef975e406a
6
+ metadata.gz: e99e8c0f20abedcbc47487dceea18a24f6166c84ebb8bff71f9bbfbf064979e8e4fcb2343642a08f566863bebe9034d654aff136114a4652393fc93aee3f4504
7
+ data.tar.gz: b6524180f0d62331a283a181534ab742f050f7d228e10973ee4a7899e20ac70702b8d9927be103bbd04984866441f394f57d9203e12f68058a3bdb99832e1df7
Binary file
data.tar.gz.sig CHANGED
@@ -1,2 +1,3 @@
1
- c"�'���b<%�����Z&I*k�\��`ђΗS:�����yq����Ky���Ӱ�у�O== �>�G�gm�Jm�.�.T~;���vߥ1�:�K
2
- M����b�0B������ﮭ(K�vY<@_�g��(�m�k�˿\��Ua�s�`����7���L��W5 ���Po�L0RnƸV����.�3�
1
+ J� 2�-���
2
+ �-�K ���]��N�����l0O��3l�Pݨؔm���{��R}:EڗQ�V+� :������P :a
3
+ �Ɲa��FW$�� �����X��B�9`+�f��C����2 �V���a�_����l]Ѣ���5���G��K=�njƢw��ܼ���?QP0rgHm�=󧩖�����Ag��Z���8:9��,uX(�36u��E�<��Ӆ�.1-�����S�#���� n���Qa���ϝJ��JG�%�q|����t�k�b��������<���Y�S�|ו���dC�\8^��I�� ��8(4[�:���<��U������ ogP�1K}(ϧ� � -���~Hb�9�
@@ -38,6 +38,10 @@ class ContactsTxt
38
38
 
39
39
  end
40
40
 
41
+ def all()
42
+ @dx.all
43
+ end
44
+
41
45
  def dx()
42
46
  @dx
43
47
  end
@@ -56,14 +60,25 @@ class ContactsTxt
56
60
 
57
61
  end
58
62
 
59
- def find_by_name(raw_name)
63
+ def find_by_name(s)
60
64
 
65
+ # Appending a hashtag to the name can help with finding the specific record
66
+ # e.g. 'Peter#plumber' or 'Peter #plumber'
67
+
68
+ raw_name, tag = s.split('#',2).map(&:strip)
69
+
61
70
  name = Regexp.new "\b#{raw_name}\b|#{raw_name}", Regexp::IGNORECASE
62
71
  puts 'name: ' + name.inspect if @debug
63
72
 
64
- @dx.all.select do |x|
73
+ a = @dx.all.select do |x|
65
74
  x.fullname =~ name or x.firstname =~ name or x.lastname =~ name
66
75
  end
76
+
77
+ if tag then
78
+ a.find {|x| x.tags.split.map(&:downcase).include? tag.downcase }
79
+ else
80
+ a
81
+ end
67
82
 
68
83
  end
69
84
 
@@ -113,6 +128,58 @@ class ContactsTxt
113
128
  @dx.filter {|x| x.mobile.length > 0}
114
129
  end
115
130
 
131
+ def multi_tel_index()
132
+
133
+ a = @dx.all.map do |x|
134
+
135
+ tel = %i(tel mobile mobile2).detect do |name|
136
+ !x.method(name).call.empty?
137
+ end
138
+ next unless tel
139
+ "%s %s" % [x.fullname, x.method(tel).call]
140
+ end.compact
141
+
142
+
143
+ # group by first name
144
+ r = a.group_by {|x| x[0]}
145
+
146
+ a2 = a.clone
147
+
148
+ # group by last name
149
+ r2 = a.group_by {|x| x.split(/ /,2).last[0]}
150
+ c = r2.merge(r)
151
+
152
+ c.each do |k, v|
153
+
154
+ puts "k: %s v: %s" % [k, v]
155
+ v.concat(r2[k]) if r2[k]
156
+
157
+ end
158
+
159
+ h = c.sort.each {|k,v| v.uniq!}.to_h
160
+
161
+ out = []
162
+
163
+ h.each do |k,v|
164
+
165
+ out << ' ' + (' ' * 30) + k
166
+
167
+ v.each do |x|
168
+
169
+ name, phone = x.split(/(?=\d)/,2)
170
+ out << "\n" + (name.length >= 29 ? name[0..26] + '...' : name)
171
+ tel = (' ' + ' ' * (26 - phone.length)) + 't: ' + phone
172
+ out << tel + "\n"
173
+ out << ('-' * 30)
174
+
175
+ end
176
+
177
+ end
178
+
179
+ puts out.join("\n")
180
+
181
+ end
182
+
116
183
  def save(filename=@filename)
117
184
 
118
185
  s = dx_to_s(@dx)
@@ -121,6 +188,10 @@ class ContactsTxt
121
188
 
122
189
  end
123
190
 
191
+ def to_dx()
192
+ @dx
193
+ end
194
+
124
195
  def to_s()
125
196
  dx_to_s @dx
126
197
  end
@@ -193,7 +264,9 @@ class ContactsTxtAgent < ContactsTxt
193
264
 
194
265
  def find_mobile_by_name(s)
195
266
 
196
- r = find_by_name(s).first
267
+ result = find_by_name(s)
268
+
269
+ r = validate(result)
197
270
 
198
271
  numbers = [r.sms.empty? ? r.mobile : r.sms, r.mobile].uniq\
199
272
  .map {|x| x.sub(/\([^\)]+\)/,'').strip}
@@ -217,7 +290,8 @@ class ContactsTxtAgent < ContactsTxt
217
290
 
218
291
  def find_tel_by_name(s)
219
292
 
220
- r = find_by_name(s).first
293
+ result = find_by_name(s)
294
+ r = validate(result)
221
295
 
222
296
  h = {}
223
297
 
@@ -229,5 +303,21 @@ class ContactsTxtAgent < ContactsTxt
229
303
 
230
304
  h[:tags] = r.tags.to_s
231
305
  h
232
- end
306
+ end
307
+
308
+ private
309
+
310
+ def validate(result)
311
+
312
+ case result.class.to_s
313
+ when 'RecordX'
314
+ result
315
+ when 'Array'
316
+ result.first
317
+ when 'NilClass'
318
+ return "I couldn't find that name."
319
+ end
320
+
321
+ end
322
+
233
323
  end
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.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,27 +10,32 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDXjCCAkagAwIBAgIBATANBgkqhkiG9w0BAQUFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTgwODAxMjEwNzA0WhcN
15
- MTkwODAxMjEwNzA0WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDC9696
17
- mu8TEN1NeSExgfozGbuajnFfKg3O4ipvtmz5qaM2BmYgxtsq/Y3JvcOmBmjXWJlL
18
- pH7PoEWZvonazT/HqYdKu9yihQ3tN5Ke/A9XvJwcz6Ug94LO0N8KgByLEBxRmSP1
19
- BYL8EpWJnhlNAffEdirPBcCLHvDl2S6RbDXyUWa03+qw6zK+Iuu9mcWoQdSxBrwU
20
- jD18mgNpVipsL1NT/dV2uz5LIESdYVA6kxvSwL2aGZ8O9c7XI8hl/9DNntRXB6BI
21
- qJ5PuYUBZVy3kOI4Ks4ra/QgaRcAGeH8f7Vl2A9SdLIYjP45CQyanHy6M8cmuwm1
22
- nSRHWQx/q3I8DhRdAgMBAAGjgYowgYcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw
23
- HQYDVR0OBBYEFBgkPuVzdzsTk+wKFFCEXg7Lb9ZyMCYGA1UdEQQfMB2BG2dlbW1h
24
- c3RlckBqYW1lc3JvYmVydHNvbi5ldTAmBgNVHRIEHzAdgRtnZW1tYXN0ZXJAamFt
25
- ZXNyb2JlcnRzb24uZXUwDQYJKoZIhvcNAQEFBQADggEBAGoMpMeiWATe9UNHf317
26
- WRymCKIukfzFSTjw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y0ymNlS0Zf7jAPWPaGHXLN
24
+ 9rMG43G0W1C65EY8RsqtJljRI3BPQQ+LJZCXc/CZJ/otv3X0dAkIKiMJbRkCAwEA
25
+ AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUwxyqw31/
26
+ OQZ4wD1Ueat8/DEscZUwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
27
+ c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
28
+ BgkqhkiG9w0BAQsFAAOCAYEAOYA65DRMrJ9boX70+jES8O+2Rb6dRl2S7qOsNHqh
29
+ 6ABXUYPSEFIg3TjxmOmoKqenfqH0EDv0nKmtCH3Sx7gYoClRgoAWXcVY+IAJV7RV
30
+ C2U68mMwEaFC4I1AazFH4QiU4KWVDRcSlXMDRHV4woccXl0DuKBKTR/P8d2Bb20Z
31
+ lB3lMzRWwCsVGeSNca3uIfxyP+kWU0c+rNV4wa6oE6+xC0aVkYZk4f2K7mk1D37V
32
+ +z1sDmCsb57rSch74/9Wenof/LnOUbUQth2NzJCdIreYaWR4maJEtHXHUq8glNsY
33
+ BivuQJVyHs/VvJ5b3/+l79zPdwOrPqZc3kSI4Pkd88ORXBwKjdSPi9elu1BmLU3M
34
+ vD5QednPC6Uz+TsskfllqEFDePfvEZbdIxgDeDjcodiGw1hVkvjsxrarBfqW/ozO
35
+ qmCJIuCwTOavNpNa1QrbiPivF5XoxOM1dEMfedK9qPxJhfovq0ZnfkMZW1R3/Qk7
36
+ N1r4i3xYGxWWiZWLrlorY10U
32
37
  -----END CERTIFICATE-----
33
- date: 2019-03-10 00:00:00.000000000 Z
38
+ date: 2020-01-05 00:00:00.000000000 Z
34
39
  dependencies:
35
40
  - !ruby/object:Gem::Dependency
36
41
  name: dynarex
@@ -41,7 +46,7 @@ dependencies:
41
46
  version: '1.8'
42
47
  - - ">="
43
48
  - !ruby/object:Gem::Version
44
- version: 1.8.17
49
+ version: 1.8.21
45
50
  type: :runtime
46
51
  prerelease: false
47
52
  version_requirements: !ruby/object:Gem::Requirement
@@ -51,7 +56,7 @@ dependencies:
51
56
  version: '1.8'
52
57
  - - ">="
53
58
  - !ruby/object:Gem::Version
54
- version: 1.8.17
59
+ version: 1.8.21
55
60
  description:
56
61
  email: james@jamesrobertson.eu
57
62
  executables: []
@@ -78,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
83
  - !ruby/object:Gem::Version
79
84
  version: '0'
80
85
  requirements: []
81
- rubygems_version: 3.0.1
86
+ rubygems_version: 3.0.3
82
87
  signing_key:
83
88
  specification_version: 4
84
89
  summary: Reads a contacts.txt file
metadata.gz.sig CHANGED
Binary file