ppl 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -0
- data/lib/ppl.rb +1 -1
- data/lib/ppl/adapter/vcard/vpim.rb +90 -58
- data/lib/ppl/command/post.rb +7 -7
- data/lib/ppl/format/address_book/postal_addresses.rb +13 -13
- data/lib/ppl/format/contact/postal_address.rb +16 -14
- data/ppl.gemspec +1 -1
- metadata +7 -7
data/README.md
CHANGED
@@ -13,6 +13,7 @@ ppl if:
|
|
13
13
|
* You prefer to keep your data stored in an open format
|
14
14
|
|
15
15
|
[![Build Status](https://secure.travis-ci.org/h2s/ppl.png)](http://travis-ci.org/h2s/ppl)
|
16
|
+
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/h2s/ppl)
|
16
17
|
|
17
18
|
Installation
|
18
19
|
------------
|
data/lib/ppl.rb
CHANGED
@@ -5,72 +5,111 @@ class Ppl::Adapter::Vcard::Vpim
|
|
5
5
|
|
6
6
|
def encode(contact)
|
7
7
|
vcard = Vpim::Vcard::Maker.make2 do |maker|
|
8
|
+
encode_birthday(contact, maker)
|
9
|
+
encode_name(contact, maker)
|
10
|
+
encode_email_addresses(contact, maker)
|
11
|
+
encode_phone_number(contact, maker)
|
12
|
+
encode_organization(contact, maker)
|
13
|
+
encode_postal_address(contact, maker)
|
14
|
+
encode_email_addresses(contact, maker)
|
15
|
+
end
|
16
|
+
vcard.to_s
|
17
|
+
end
|
8
18
|
|
9
|
-
|
10
|
-
|
11
|
-
|
19
|
+
def decode(string)
|
20
|
+
vcard = Vpim::Vcard.decode(string).first
|
21
|
+
contact = Ppl::Entity::Contact.new
|
22
|
+
decode_birthday(vcard, contact)
|
23
|
+
decode_email_addresses(vcard, contact)
|
24
|
+
decode_phone_number(vcard, contact)
|
25
|
+
decode_postal_address(vcard, contact)
|
26
|
+
decode_organization(vcard, contact)
|
27
|
+
decode_name(vcard, contact)
|
28
|
+
return contact
|
29
|
+
end
|
12
30
|
|
13
|
-
maker.add_name do |name|
|
14
|
-
name.given = contact.id unless contact.id.nil?
|
15
|
-
name.fullname = contact.name unless contact.name.nil?
|
16
|
-
end
|
17
31
|
|
18
|
-
|
19
|
-
maker.add_email(email_address)
|
20
|
-
end
|
32
|
+
private
|
21
33
|
|
22
|
-
|
23
|
-
|
24
|
-
|
34
|
+
def encode_birthday(contact, vcard_maker)
|
35
|
+
if !contact.birthday.nil?
|
36
|
+
vcard_maker.birthday = contact.birthday
|
37
|
+
end
|
38
|
+
end
|
25
39
|
|
26
|
-
|
27
|
-
|
28
|
-
|
40
|
+
def encode_name(contact, vcard_maker)
|
41
|
+
vcard_maker.add_name do |name|
|
42
|
+
name.given = contact.id unless contact.id.nil?
|
43
|
+
name.fullname = contact.name unless contact.name.nil?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def encode_email_addresses(contact, vcard_maker)
|
48
|
+
contact.email_addresses.each do |email_address|
|
49
|
+
vcard_maker.add_email(email_address)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def encode_phone_number(contact, vcard_maker)
|
54
|
+
if !contact.phone_number.nil?
|
55
|
+
vcard_maker.add_tel(contact.phone_number)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def encode_organization(contact, vcard_maker)
|
60
|
+
if !contact.organization.nil?
|
61
|
+
vcard_maker.org=(contact.organization)
|
62
|
+
end
|
63
|
+
end
|
29
64
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
65
|
+
def encode_postal_address(contact, vcard_maker)
|
66
|
+
if !contact.postal_address.nil?
|
67
|
+
vcard_maker.add_addr do |address|
|
68
|
+
if !contact.postal_address.street.nil?
|
69
|
+
address.street = contact.postal_address.street
|
70
|
+
end
|
71
|
+
if !contact.postal_address.postal_code.nil?
|
72
|
+
address.postalcode = contact.postal_address.postal_code
|
73
|
+
end
|
74
|
+
if !contact.postal_address.po_box.nil?
|
75
|
+
address.pobox = contact.postal_address.po_box
|
76
|
+
end
|
77
|
+
if !contact.postal_address.country.nil?
|
78
|
+
address.country = contact.postal_address.country
|
79
|
+
end
|
80
|
+
if !contact.postal_address.region.nil?
|
81
|
+
address.region = contact.postal_address.region
|
82
|
+
end
|
83
|
+
if !contact.postal_address.locality.nil?
|
84
|
+
address.locality = contact.postal_address.locality
|
50
85
|
end
|
51
86
|
end
|
52
|
-
|
53
87
|
end
|
88
|
+
end
|
54
89
|
|
55
|
-
|
90
|
+
def decode_birthday(vcard, contact)
|
91
|
+
contact.birthday = vcard.birthday unless vcard.birthday.nil?
|
56
92
|
end
|
57
93
|
|
58
|
-
def
|
59
|
-
vcard
|
60
|
-
|
94
|
+
def decode_name(vcard, contact)
|
95
|
+
if !vcard.name.nil?
|
96
|
+
contact.name = vcard.name.fullname
|
97
|
+
end
|
98
|
+
end
|
61
99
|
|
62
|
-
|
63
|
-
|
100
|
+
def decode_organization(vcard, contact)
|
101
|
+
if !vcard.org.nil?
|
102
|
+
contact.organization = vcard.org.first
|
64
103
|
end
|
104
|
+
end
|
65
105
|
|
106
|
+
def decode_email_addresses(vcard, contact)
|
66
107
|
vcard.emails.each do |email|
|
67
108
|
contact.email_addresses.push(email.to_s)
|
68
109
|
end
|
110
|
+
end
|
69
111
|
|
70
|
-
|
71
|
-
contact.phone_number = vcard.telephones.first
|
72
|
-
end
|
73
|
-
|
112
|
+
def decode_postal_address(vcard, contact)
|
74
113
|
if !vcard.address.nil?
|
75
114
|
contact.postal_address = Ppl::Entity::PostalAddress.new
|
76
115
|
contact.postal_address.street = vcard.address.street
|
@@ -80,19 +119,12 @@ class Ppl::Adapter::Vcard::Vpim
|
|
80
119
|
contact.postal_address.region = vcard.address.region
|
81
120
|
contact.postal_address.country = vcard.address.country
|
82
121
|
end
|
122
|
+
end
|
83
123
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
name = nil
|
89
|
-
name = vcard.name
|
90
|
-
|
91
|
-
if !name.nil?
|
92
|
-
contact.name = name.fullname
|
124
|
+
def decode_phone_number(vcard, contact)
|
125
|
+
if !vcard.telephones.empty?
|
126
|
+
contact.phone_number = vcard.telephones.first
|
93
127
|
end
|
94
|
-
|
95
|
-
return contact
|
96
128
|
end
|
97
129
|
|
98
130
|
end
|
data/lib/ppl/command/post.rb
CHANGED
@@ -72,14 +72,14 @@ class Ppl::Command::Post < Ppl::Application::Command
|
|
72
72
|
|
73
73
|
def set_postal_address(input, output)
|
74
74
|
contact = @storage.require_contact(input.arguments[0])
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
address.street = input.options[:street] unless input.options[:street].nil?
|
75
|
+
|
76
|
+
[:country, :locality, :region, :po_box, :postal_code, :street].each do |property|
|
77
|
+
next if input.options[property].nil?
|
78
|
+
contact.set_postal_address do |address|
|
79
|
+
address.send("#{property.to_s}=", input.options[property])
|
80
|
+
end
|
82
81
|
end
|
82
|
+
|
83
83
|
@storage.save_contact(contact)
|
84
84
|
end
|
85
85
|
|
@@ -16,27 +16,27 @@ class Ppl::Format::AddressBook::PostalAddresses < Ppl::Format::AddressBook
|
|
16
16
|
private
|
17
17
|
|
18
18
|
def add_row(contact)
|
19
|
-
id = sprintf("%s:", contact.id)
|
20
19
|
postal_address = nil
|
21
|
-
|
22
20
|
if !contact.postal_address.nil?
|
23
|
-
|
24
|
-
contact.postal_address.street,
|
25
|
-
contact.postal_address.locality,
|
26
|
-
contact.postal_address.region,
|
27
|
-
contact.postal_address.country,
|
28
|
-
contact.postal_address.postal_code,
|
29
|
-
contact.postal_address.po_box,
|
30
|
-
].select { |property| property != "" && !property.nil? }
|
31
|
-
postal_address = pieces.join(", ")
|
21
|
+
postal_address = format_postal_address(contact.postal_address)
|
32
22
|
end
|
33
|
-
|
34
23
|
@table.add_row({
|
35
|
-
:id => id,
|
24
|
+
:id => sprintf("%s:", contact.id),
|
36
25
|
:postal_address => postal_address,
|
37
26
|
})
|
38
27
|
end
|
39
28
|
|
29
|
+
def format_postal_address(postal_address)
|
30
|
+
pieces = [
|
31
|
+
postal_address.street,
|
32
|
+
postal_address.locality,
|
33
|
+
postal_address.region,
|
34
|
+
postal_address.country,
|
35
|
+
postal_address.postal_code,
|
36
|
+
postal_address.po_box,
|
37
|
+
].select { |property| property != "" && !property.nil? }
|
38
|
+
pieces.join(", ")
|
39
|
+
end
|
40
40
|
|
41
41
|
end
|
42
42
|
|
@@ -10,20 +10,22 @@ class Ppl::Format::Contact::PostalAddress < Ppl::Format::Contact
|
|
10
10
|
def process(contact)
|
11
11
|
address = contact.postal_address
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
13
|
+
if !address.nil?
|
14
|
+
{
|
15
|
+
:street => "Street",
|
16
|
+
:postal_code => "Postal Code",
|
17
|
+
:po_box => "PO box",
|
18
|
+
:locality => "Locality",
|
19
|
+
:region => "Region",
|
20
|
+
:country => "Country",
|
21
|
+
}.each do |property, name|
|
22
|
+
value = address.send(property)
|
23
|
+
next if value.nil? || value == ""
|
24
|
+
@table.add_row({
|
25
|
+
:label => sprintf("%s:", name),
|
26
|
+
:value => address.send(property)
|
27
|
+
})
|
28
|
+
end
|
27
29
|
end
|
28
30
|
|
29
31
|
return @table.to_s
|
data/ppl.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ppl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-12-20 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: inifile
|
16
|
-
requirement: &
|
16
|
+
requirement: &14299780 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - =
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.0.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *14299780
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rugged
|
27
|
-
requirement: &
|
27
|
+
requirement: &14298340 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - =
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.17.0.b6
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *14298340
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: vpim
|
38
|
-
requirement: &
|
38
|
+
requirement: &14297560 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - =
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0.695'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *14297560
|
47
47
|
description: CLI Address Book
|
48
48
|
email: henry@henrysmith.org
|
49
49
|
executables:
|