contacts_txt 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/contacts_txt.rb +76 -0
- metadata +87 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f64f636af43564a972be03194347dcefbb3ba530
|
4
|
+
data.tar.gz: 5737297dfe22c8170439a04523c2c9704f7db98a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d322402305545cbbdb64ca8d4163b00c9ca5e2a02fe78c80c4f27cd05125ca38431278fa341c7299e3641152e3d2677c87134ce473683b371b16e77c423b3e96
|
7
|
+
data.tar.gz: 962b91e23c431f1e8b80e7f4caa2f80280415088a7cb8dbc48f07711d9f8ed03507fdf696af6c7b406da0ca9bef6005fb3482c99f1cece3830e5b96a2618d957
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
data/lib/contacts_txt.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: contacts_txt.rb
|
4
|
+
|
5
|
+
require 'dynarex'
|
6
|
+
|
7
|
+
|
8
|
+
class ContactsTxt
|
9
|
+
|
10
|
+
attr_reader :to_s
|
11
|
+
|
12
|
+
def initialize(filename='contacts.txt', path: '.', \
|
13
|
+
fields: %w(tags email address notes))
|
14
|
+
@fields = %w(fullname firstname lastname tel) | fields
|
15
|
+
@filename, @path = filename, path
|
16
|
+
|
17
|
+
fpath = File.join(path, filename)
|
18
|
+
|
19
|
+
@dx = if File.exists?(fpath) then
|
20
|
+
import_to_dx(File.read(fpath))
|
21
|
+
else
|
22
|
+
new_dx()
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def dx()
|
27
|
+
@dx
|
28
|
+
end
|
29
|
+
|
30
|
+
def save(filename=@filename)
|
31
|
+
|
32
|
+
s = dx_to_s(@dx, title: File.basename(filename) )
|
33
|
+
File.write File.join(@path, filename), s
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s()
|
38
|
+
dx_to_s @dx
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def dx_to_s(dx, title: File.basename(@filename))
|
44
|
+
|
45
|
+
rows = dx.all.map do |row|
|
46
|
+
|
47
|
+
h = row.to_h
|
48
|
+
|
49
|
+
fullname = h.delete :fullname
|
50
|
+
h.delete :firstname
|
51
|
+
h.delete :lastname
|
52
|
+
a = h.to_a.reject! {|k,v| v.empty?}
|
53
|
+
|
54
|
+
([fullname] + a.map {|x| x.join(': ') }).join("\n")
|
55
|
+
end
|
56
|
+
|
57
|
+
"%s\n%s\n\n%s" % [title, '=' * title.length, rows.join("\n\n")]
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
def import_to_dx(raw_s)
|
62
|
+
|
63
|
+
s = raw_s.lstrip.lines[2..-1].join.strip.\
|
64
|
+
split(/\s+(?=^[\w\s]+$)/).map {|x| 'fullname: ' + x }.join("\n")
|
65
|
+
|
66
|
+
new_dx().import "--+\n" + s
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
def new_dx()
|
71
|
+
|
72
|
+
Dynarex.new "contacts/contact(#{@fields.join ', '})"
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: contacts_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
|
+
MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEA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Jy4JYNRZug/LzuxXv51IWa3yN+b/JIybQobdUsLP3W4xng+mS
|
29
|
+
zydGYLPehHYag4MtK+hb3L9uYj/NDWKgSBi5aTm2p8r+e0pHrhRHDwbl+gtKDjyn
|
30
|
+
ij71NTxNLGkHUd4D7WadOvkDzpCrz8uQ8EJktnsidwvlyTq/ZdmiQ0WhfLFYjjeN
|
31
|
+
8BrWDFGNkIWV3yB/gSHs8fdeilDhOC6aNlKtykxtMiM68u+9GhOj3HtgmLAdp9zC
|
32
|
+
m8j9CN8cBtwSBA==
|
33
|
+
-----END CERTIFICATE-----
|
34
|
+
date: 2015-12-13 00:00:00.000000000 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.5'
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.5.44
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '1.5'
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.5.44
|
56
|
+
description:
|
57
|
+
email: james@r0bertson.co.uk
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/contacts_txt.rb
|
63
|
+
homepage: https://github.com/jrobertson/contacts_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.4.8
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Reads a contacts.txt file
|
87
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|