ppl 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ppl.rb +3 -1
- data/lib/ppl/format/contact/full.rb +33 -15
- data/lib/ppl/format/postal_address.rb +9 -0
- data/lib/ppl/format/postal_address/one_line.rb +18 -0
- data/ppl.gemspec +2 -2
- data/spec/ppl/format/contact/full_spec.rb +11 -2
- data/spec/ppl/format/postal_address/one_line_spec.rb +44 -0
- data/spec/ppl/format/postal_address_spec.rb +18 -0
- metadata +12 -8
data/lib/ppl.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module Ppl
|
3
3
|
|
4
|
-
Version = "1.
|
4
|
+
Version = "1.7.0"
|
5
5
|
|
6
6
|
module Adapter
|
7
7
|
end
|
@@ -80,6 +80,8 @@ require "ppl/format/contact/name"
|
|
80
80
|
require "ppl/format/contact/organization"
|
81
81
|
require "ppl/format/contact/phone_number"
|
82
82
|
require "ppl/format/contact/postal_address"
|
83
|
+
require "ppl/format/postal_address"
|
84
|
+
require "ppl/format/postal_address/one_line"
|
83
85
|
require "ppl/format/table"
|
84
86
|
|
85
87
|
class String
|
@@ -4,31 +4,28 @@ class Ppl::Format::Contact::Full < Ppl::Format::Contact
|
|
4
4
|
attr_writer :postal_address_format
|
5
5
|
|
6
6
|
def initialize
|
7
|
-
@postal_address_format = Ppl::Format::
|
7
|
+
@postal_address_format = Ppl::Format::PostalAddress::OneLine.new
|
8
8
|
end
|
9
9
|
|
10
10
|
def process(contact)
|
11
|
-
lines = []
|
11
|
+
@lines = []
|
12
12
|
|
13
13
|
first_line = first_line(contact)
|
14
14
|
if first_line != ""
|
15
|
-
lines.push(first_line)
|
15
|
+
@lines.push(first_line)
|
16
16
|
end
|
17
17
|
|
18
18
|
vitals = vitals(contact)
|
19
19
|
if vitals != ""
|
20
|
-
lines.push("")
|
21
|
-
lines.push(vitals)
|
22
|
-
lines.push("")
|
23
|
-
lines.push("")
|
20
|
+
@lines.push("")
|
21
|
+
@lines.push(vitals)
|
24
22
|
end
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
24
|
+
format_email_addresses(contact)
|
25
|
+
format_phone_numbers(contact)
|
26
|
+
format_postal_addresses(contact)
|
30
27
|
|
31
|
-
return lines.join("\n")
|
28
|
+
return @lines.join("\n")
|
32
29
|
end
|
33
30
|
|
34
31
|
private
|
@@ -49,9 +46,6 @@ class Ppl::Format::Contact::Full < Ppl::Format::Contact
|
|
49
46
|
if !contact.birthday.nil?
|
50
47
|
vitals.push(format_vital("Birthday", contact.birthday.strftime("%Y-%m-%d")))
|
51
48
|
end
|
52
|
-
if !contact.phone_number.nil?
|
53
|
-
vitals.push(format_vital("Telephone", contact.phone_number))
|
54
|
-
end
|
55
49
|
if !contact.organization.nil?
|
56
50
|
vitals.push(format_vital("Organization", contact.organization))
|
57
51
|
end
|
@@ -62,5 +56,29 @@ class Ppl::Format::Contact::Full < Ppl::Format::Contact
|
|
62
56
|
return sprintf(" %-12s %s", name, value)
|
63
57
|
end
|
64
58
|
|
59
|
+
def format_email_addresses(contact)
|
60
|
+
if !contact.email_addresses.empty?
|
61
|
+
@lines.push("")
|
62
|
+
@lines.push("Email Addresses:")
|
63
|
+
contact.email_addresses.each { |email_address| @lines.push(" " + email_address) }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def format_phone_numbers(contact)
|
68
|
+
if !contact.phone_number.nil?
|
69
|
+
@lines.push("")
|
70
|
+
@lines.push("Phone Numbers:")
|
71
|
+
@lines.push(" #{contact.phone_number}")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def format_postal_addresses(contact)
|
76
|
+
if !contact.postal_address.nil?
|
77
|
+
@lines.push("")
|
78
|
+
@lines.push("Postal Address:")
|
79
|
+
@lines.push(" " + @postal_address_format.process(contact.postal_address))
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
65
83
|
end
|
66
84
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
class Ppl::Format::PostalAddress::OneLine < Ppl::Format::AddressBook
|
3
|
+
|
4
|
+
def process(postal_address)
|
5
|
+
pieces = []
|
6
|
+
|
7
|
+
pieces.push(postal_address.street) unless postal_address.street.nil?
|
8
|
+
pieces.push(postal_address.locality) unless postal_address.locality.nil?
|
9
|
+
pieces.push(postal_address.region) unless postal_address.region.nil?
|
10
|
+
pieces.push(postal_address.country) unless postal_address.country.nil?
|
11
|
+
pieces.push(postal_address.postal_code) unless postal_address.postal_code.nil?
|
12
|
+
pieces.push(postal_address.po_box) unless postal_address.po_box.nil?
|
13
|
+
|
14
|
+
pieces.join(", ")
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
data/ppl.gemspec
CHANGED
@@ -24,7 +24,16 @@ describe Ppl::Format::Contact::Full do
|
|
24
24
|
it "should include their email address in brackets" do
|
25
25
|
@contact.name = "John Doe"
|
26
26
|
@contact.email_addresses.push "john@example.org"
|
27
|
-
@format.process(@contact).should
|
27
|
+
@format.process(@contact).should include "John Doe <john@example.org>"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should show all their email addresses" do
|
31
|
+
@contact.email_addresses.push "john@example.org"
|
32
|
+
@contact.email_addresses.push "john@example.com"
|
33
|
+
@contact.email_addresses.push "john@example.net"
|
34
|
+
@format.process(@contact).should include "john@example.org"
|
35
|
+
@format.process(@contact).should include "john@example.com"
|
36
|
+
@format.process(@contact).should include "john@example.net"
|
28
37
|
end
|
29
38
|
|
30
39
|
it "should show their birthday if available" do
|
@@ -44,7 +53,7 @@ describe Ppl::Format::Contact::Full do
|
|
44
53
|
|
45
54
|
it "should show their postal address if available" do
|
46
55
|
@contact.postal_address = @address
|
47
|
-
@postal_address_format.should_receive(:process).
|
56
|
+
@postal_address_format.should_receive(:process).and_return("")
|
48
57
|
@format.process(@contact)
|
49
58
|
end
|
50
59
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
describe Ppl::Format::PostalAddress::OneLine do
|
3
|
+
|
4
|
+
before(:each) do
|
5
|
+
@format = Ppl::Format::PostalAddress::OneLine.new
|
6
|
+
@address = Ppl::Entity::PostalAddress.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#process" do
|
10
|
+
|
11
|
+
it "should include the country if available" do
|
12
|
+
@address.country = "UK"
|
13
|
+
@format.process(@address).should include "UK"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should include the locality if available" do
|
17
|
+
@address.locality = "Liverpool"
|
18
|
+
@format.process(@address).should include "Liverpool"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should include the street if available" do
|
22
|
+
@address.street = "1 Test Road"
|
23
|
+
@format.process(@address).should include "1 Test Road"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should include the po box if available" do
|
27
|
+
@address.po_box = "123456"
|
28
|
+
@format.process(@address).should include "123456"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should include the postal code if available" do
|
32
|
+
@address.postal_code = "L1 9AA"
|
33
|
+
@format.process(@address).should include "L1 9AA"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should include the region if available" do
|
37
|
+
@address.region = "Merseyside"
|
38
|
+
@format.process(@address).should include "Merseyside"
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
describe Ppl::Format::PostalAddress do
|
3
|
+
|
4
|
+
before(:each) do
|
5
|
+
@format = Ppl::Format::PostalAddress.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#process" do
|
9
|
+
|
10
|
+
it "should raise a NotImplementedError" do
|
11
|
+
expect{@format.process(nil)}.to raise_error(NotImplementedError)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
|
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.
|
4
|
+
version: 1.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: inifile
|
16
|
-
requirement: &
|
16
|
+
requirement: &7003600 !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: *7003600
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rugged
|
27
|
-
requirement: &
|
27
|
+
requirement: &7002340 !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: *7002340
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: vpim
|
38
|
-
requirement: &
|
38
|
+
requirement: &7001560 !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: *7001560
|
47
47
|
description: CLI Address Book
|
48
48
|
email: henry@henrysmith.org
|
49
49
|
executables:
|
@@ -111,6 +111,8 @@ files:
|
|
111
111
|
- lib/ppl/format/contact/organization.rb
|
112
112
|
- lib/ppl/format/contact/phone_number.rb
|
113
113
|
- lib/ppl/format/contact/postal_address.rb
|
114
|
+
- lib/ppl/format/postal_address.rb
|
115
|
+
- lib/ppl/format/postal_address/one_line.rb
|
114
116
|
- lib/ppl/format/table.rb
|
115
117
|
- ppl.gemspec
|
116
118
|
- spec/ppl/adapter/output_spec.rb
|
@@ -162,6 +164,8 @@ files:
|
|
162
164
|
- spec/ppl/format/contact/phone_number_spec.rb
|
163
165
|
- spec/ppl/format/contact/postal_address_spec.rb
|
164
166
|
- spec/ppl/format/contact_spec.rb
|
167
|
+
- spec/ppl/format/postal_address/one_line_spec.rb
|
168
|
+
- spec/ppl/format/postal_address_spec.rb
|
165
169
|
- spec/ppl/format/table_spec.rb
|
166
170
|
- spec/spec_helper.rb
|
167
171
|
homepage: http://ppladdressbook.org
|