addressbook_txt 0.2.1 → 0.3.0

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
  SHA1:
3
- metadata.gz: e26a9f61a1a9f134d0bce159197382d41a3faab9
4
- data.tar.gz: c0f83c8ca76827f2ec822d1dcdb15fbd410d0f29
3
+ metadata.gz: 7eb28b52f74e5eddd7ba29cf99fe876493135fb9
4
+ data.tar.gz: 0e4010cc8713b00ccf99eafae500498fc65e3884
5
5
  SHA512:
6
- metadata.gz: 4d2275704f49a165e149d09e3d11b9ded04f4aea5b86da68fd93631c4f5ee112335fb8c60bee333515cbf7016295ebc2d4c53e3536a2e68765722d9a62c6f509
7
- data.tar.gz: 4884dd5e2e0e5299d8105c085cb25f5309c7f23abc4aa6317784ef427fa29fdc38ea8e16874cbf2e15121cd1435b15a0f5b18627ef033d34ed86a55af60c5d7a
6
+ metadata.gz: 1838fbdd33342235cf1b240ed314fbacb459712ef59db0f2d02e99903f85df9ec1cda3195b2c2b9dc078f918120cd40064ef3d55a603a13b54a79656101046ed
7
+ data.tar.gz: e6d3488ee1bdecd38db53ae0e5faededa9c7f1ea0731a0c8f004a391bf7219e41b0d715d7ea3acc768a56f4d709951700de1faccdbd4ef1aed7ef94fb0d75532
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -15,31 +15,30 @@ require 'rexle-diff'
15
15
  # [x] read an existing addressbook.txt file
16
16
  # [x] search each entry using a keyword
17
17
  # [x] archive address entries on an annual basis
18
- # [ ] search the archive using a keyword
18
+ # [x] search the archive using a keyword
19
19
 
20
20
 
21
21
 
22
22
  class AddressbookTxt
23
23
 
24
- attr_reader :to_s
24
+ attr_reader :to_s, :dx
25
25
 
26
- def initialize(filename='addressbook.txt', path: '.')
26
+ def initialize(filename='addressbook.txt', path: File.dirname(filename))
27
27
 
28
- @filename, @path = filename, path
28
+ @filename, @path = File.basename(filename), File.expand_path(path)
29
29
 
30
- fpath = File.join(path, filename)
30
+ fpath = File.join(@path, @filename)
31
31
 
32
- if File.exists?(fpath) then
32
+ @dx = if File.exists?(fpath) then
33
+
34
+ s = File.read(fpath)
35
+
36
+ File.extname(@filename) == '.txt' ? import_to_dx(s) : Dynarex.new(s)
33
37
 
34
- @dx = import_to_dx(File.read(fpath))
35
-
36
38
  else
37
- @dx = new_dx
39
+ new_dx()
38
40
  end
39
- end
40
-
41
- def dx()
42
- @dx
41
+
43
42
  end
44
43
 
45
44
  def save(filename=@filename)
@@ -67,7 +66,22 @@ class AddressbookTxt
67
66
  end
68
67
 
69
68
  def search(keyword)
70
- dx.all.select {|r| r.x =~ /#{keyword}/i}
69
+
70
+ found = dx.all.select {|r| r.x =~ /#{keyword}/i}
71
+
72
+ if found.empty? then
73
+
74
+ # search the archive
75
+
76
+ archive_files = File.join(@path,'archive','addressbook-*.xml')
77
+
78
+ found = Dir.glob(archive_files).sort.reverse[1..-1].flat_map do |file|
79
+ AddressbookTxt.new(file).search keyword
80
+ end
81
+ end
82
+
83
+ return found
84
+
71
85
  end
72
86
 
73
87
  def to_s()
@@ -107,5 +121,4 @@ class AddressbookTxt
107
121
 
108
122
  end
109
123
 
110
-
111
124
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addressbook_txt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file