addressbook_txt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6be7f563f146ed0557a69e8f3ff7b889b258fef3
4
+ data.tar.gz: 2e20375e9744639159d0369d6ad26238f379ca14
5
+ SHA512:
6
+ metadata.gz: 47c17b110eab42a2bc2200e03d00be607b16e0584a04c6c82d5dc0bd7fc6a470d6c746ecc6cca3fd68b23d8f400f0e00e56ea1439e6caf99c6c9c6518c8fdc86
7
+ data.tar.gz: 14abba25611b670e35843a0682e7203a61446ecce55be670a7ba9c5807b106e888ae785ed0e53d553835a4c0188a9abe785575710d51a846be4f31dddcef344a
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
@@ -0,0 +1 @@
1
+ ��a *d���'ͺ^x��� <,j�Ѷ�ފ�M��`������JL��[R������J��M��P�cQ���͡e���H��/� �fԌ�"����W�o?$�PS�F�7+���OR����F3\�d�;s�|�|��U�&^�ٻN�c*~�n��e�k0 #4$Hw�"7q��s�s�)��"0��Nj`k,>%q"+� �@�V����.f� ��׉�>(�5s�ƯǶ5�.��7M�Q�#�"n[W����fu��7�
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: addressbook_txt.rb
4
+
5
+ require 'date'
6
+ require 'dynarex'
7
+ require 'fileutils'
8
+
9
+
10
+
11
+ # The AddressbookTxt gem can:
12
+ #
13
+ # [x] create a new addressbook.txt file
14
+ # [x] read an existing addressbook.txt file
15
+ # [ ] search each entry using a keyword
16
+ # [ ] archive address entries on an annual basis
17
+ # [ ] search the archive using a keyword
18
+
19
+
20
+
21
+ class AddressbookTxt
22
+
23
+ attr_reader :to_s
24
+
25
+ def initialize(filename='addressbook.txt', path: '.')
26
+
27
+ @filename, @path = filename, path
28
+
29
+ fpath = File.join(path, filename)
30
+
31
+ if File.exists?(fpath) then
32
+
33
+ @dx = import_to_dx(File.read(fpath))
34
+
35
+ else
36
+ @dx = new_dx
37
+ end
38
+ end
39
+
40
+ def dx()
41
+ @dx
42
+ end
43
+
44
+ def save(filename=@filename)
45
+
46
+ s = File.basename(filename) + "\n" + dx_to_s(@dx).lines[1..-1].join
47
+ File.write File.join(@path, filename), s
48
+ @dx.save File.join(@path, filename.sub(/\.txt$/,'.xml'))
49
+
50
+ end
51
+
52
+ def to_s()
53
+ dx_to_s @dx
54
+ end
55
+
56
+ private
57
+
58
+ def dx_to_s(dx)
59
+
60
+ title = File.basename(@filename)
61
+ title + "\n" + "=" * title.length + "\n\n%s\n\n" % [dx.to_s(header: false)]
62
+
63
+ end
64
+
65
+ def import_to_dx(s)
66
+
67
+ a = s.lines
68
+ # Remove the heading
69
+ a.shift 2
70
+
71
+ # add the sectionx raw document type
72
+ a.unshift '--#'
73
+
74
+ dx = new_dx()
75
+ dx.import(a.join)
76
+
77
+ return dx
78
+ end
79
+
80
+ def new_dx()
81
+
82
+ dx = Dynarex.new 'addresses[title]/address(x)'
83
+ dx.title = "Address Book"
84
+
85
+ return dx
86
+
87
+ end
88
+
89
+
90
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: addressbook_txt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
+ YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
+ 8ixkARkWAmV1MB4XDTE2MDcyMzE4NDA1MFoXDTE3MDcyMzE4NDA1MFowSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
+ EjAQBgoJkia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000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: dynarex
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.7'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 1.7.12
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.7'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 1.7.12
56
+ description:
57
+ email: james@r0bertson.co.uk
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/addressbook_txt.rb
63
+ homepage: https://github.com/jrobertson/addressbook_txt
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.5.1
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Stores address book entries in a plain text file
87
+ test_files: []
metadata.gz.sig ADDED
Binary file