addressbook_txt 0.2.1 → 0.3.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.tar.gz.sig +0 -0
- data/lib/addressbook_txt.rb +28 -15
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7eb28b52f74e5eddd7ba29cf99fe876493135fb9
|
|
4
|
+
data.tar.gz: 0e4010cc8713b00ccf99eafae500498fc65e3884
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1838fbdd33342235cf1b240ed314fbacb459712ef59db0f2d02e99903f85df9ec1cda3195b2c2b9dc078f918120cd40064ef3d55a603a13b54a79656101046ed
|
|
7
|
+
data.tar.gz: e6d3488ee1bdecd38db53ae0e5faededa9c7f1ea0731a0c8f004a391bf7219e41b0d715d7ea3acc768a56f4d709951700de1faccdbd4ef1aed7ef94fb0d75532
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data.tar.gz.sig
CHANGED
|
Binary file
|
data/lib/addressbook_txt.rb
CHANGED
|
@@ -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
|
-
# [
|
|
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
|
-
|
|
39
|
+
new_dx()
|
|
38
40
|
end
|
|
39
|
-
|
|
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
|
-
|
|
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
metadata.gz.sig
CHANGED
|
Binary file
|