ppl 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae020954e5c508fd1ea28a2bfb193fbb6393252d
4
- data.tar.gz: 9d5b69c1e111f93bf92451dfcb4bc448de214393
3
+ metadata.gz: 95e88afd4d3b0aa9e6af8d3e5362b8826ff0a338
4
+ data.tar.gz: 4dd553d7deaeb6880d958c92c9797230c8a601d4
5
5
  SHA512:
6
- metadata.gz: 1fae903da342d62e76058b006313c3bad706a4faa509fb3792177bc5eb0e2803c2993f11d491f820503dceea8b1b1bd6905e4183aaeaef8f8d5809bdc03427fe
7
- data.tar.gz: ad1fd41a18934622b4d78f6f59c79b13513f0242c2f50ae33fb68bc7d50909233fd19ab5fa037594b03270831cfe16b172c7429a9501c9594d28df5f9f7c7bd5
6
+ metadata.gz: 77825be6cccd5eda789c2ae779c94fccea8e19b703f880b22e13dd7c4acd68e26e57963feddd0e77a3bf48a8aa28d33f83973ad84075427d408570889216feab
7
+ data.tar.gz: 5d4b42a641b6c9f7fe3d048afcbed0009eaab79262495e6d0c944a05ebf6179802a508b6aac0308abe048d88915bebf862bd2789a45d44e0967554f2d77ed183
data/lib/ppl.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Ppl
3
3
 
4
- Version = "2.0.0"
4
+ Version = "2.1.0"
5
5
 
6
6
  module Adapter
7
7
  end
@@ -74,6 +74,7 @@ require "ppl/command/scrape"
74
74
  require "ppl/entity/address_book"
75
75
  require "ppl/entity/contact"
76
76
  require "ppl/entity/email_address"
77
+ require "ppl/entity/name"
77
78
  require "ppl/entity/phone_number"
78
79
  require "ppl/entity/postal_address"
79
80
 
@@ -99,7 +100,6 @@ require "ppl/format/contact/age"
99
100
  require "ppl/format/contact/birthday"
100
101
  require "ppl/format/contact/email_addresses"
101
102
  require "ppl/format/contact/full"
102
- require "ppl/format/contact/name"
103
103
  require "ppl/format/contact/nicknames"
104
104
  require "ppl/format/contact/organization"
105
105
  require "ppl/format/contact/phone_number"
@@ -110,12 +110,15 @@ require "ppl/format/custom"
110
110
  require "ppl/format/custom/contact"
111
111
  require "ppl/format/custom/email_address"
112
112
  require "ppl/format/custom/phone_number"
113
+ require "ppl/format/name"
114
+ require "ppl/format/name/full_only"
113
115
  require "ppl/format/postal_address"
114
116
  require "ppl/format/postal_address/multi_line"
115
117
  require "ppl/format/postal_address/one_line"
116
118
  require "ppl/format/table"
117
119
 
118
120
  require "ppl/service/email_address"
121
+ require "ppl/service/name"
119
122
  require "ppl/service/phone_number"
120
123
  require "ppl/service/postal_address"
121
124
 
@@ -53,8 +53,12 @@ class Ppl::Adapter::Vcard::GreenCard
53
53
 
54
54
  def encode_name(contact, vcard_maker)
55
55
  vcard_maker.add_name do |name|
56
- name.given = contact.id unless contact.id.nil?
57
- name.fullname = contact.name unless contact.name.nil?
56
+ name.given = contact.name.given unless contact.name.given.nil?
57
+ name.family = contact.name.family unless contact.name.family.nil?
58
+ name.additional = contact.name.middle unless contact.name.middle.nil?
59
+ name.fullname = contact.name.full unless contact.name.full.nil?
60
+ name.prefix = contact.name.prefix unless contact.name.prefix.nil?
61
+ name.suffix = contact.name.suffix unless contact.name.suffix.nil?
58
62
  end
59
63
  end
60
64
 
@@ -112,8 +116,9 @@ class Ppl::Adapter::Vcard::GreenCard
112
116
  end
113
117
 
114
118
  def decode_name(vcard, contact)
119
+ contact.name = Ppl::Entity::Name.new
115
120
  if !vcard.name.nil?
116
- contact.name = vcard.name.fullname
121
+ contact.name.full = vcard.name.fullname
117
122
  end
118
123
  end
119
124
 
@@ -8,6 +8,7 @@ class Ppl::Application::Bootstrap
8
8
  register :command_add do
9
9
  add = Ppl::Command::Add.new
10
10
  add.storage = storage_adapter
11
+ add.name_service = name_service
11
12
  add
12
13
  end
13
14
 
@@ -82,7 +83,8 @@ class Ppl::Application::Bootstrap
82
83
  name = Ppl::Command::Name.new
83
84
  name.storage = storage_adapter
84
85
  name.list_format = format_address_book_names
85
- name.show_format = format_contact_name
86
+ name.show_format = format_name_full_only
87
+ name.name_service = name_service
86
88
  name
87
89
  end
88
90
 
@@ -299,9 +301,9 @@ class Ppl::Application::Bootstrap
299
301
  Ppl::Format::Contact::EmailAddresses.new(colors)
300
302
  end
301
303
 
302
- register :format_contact_name do
304
+ register :format_name_full_only do
303
305
  colors = configuration.command_colors("name")
304
- Ppl::Format::Contact::Name.new(colors)
306
+ Ppl::Format::Name::FullOnly.new(colors)
305
307
  end
306
308
 
307
309
  register :format_contact_nicknames do
@@ -377,6 +379,11 @@ class Ppl::Application::Bootstrap
377
379
  email_service
378
380
  end
379
381
 
382
+ register :name_service do
383
+ name_service = Ppl::Service::Name.new
384
+ name_service
385
+ end
386
+
380
387
  register :phone_service do
381
388
  phone_service = Ppl::Service::PhoneNumber.new
382
389
  phone_service.storage = storage_adapter
@@ -1,6 +1,8 @@
1
1
 
2
2
  class Ppl::Command::Add < Ppl::Application::Command
3
3
 
4
+ attr_writer :name_service
5
+
4
6
  name "add"
5
7
  description "Add a new contact"
6
8
 
@@ -22,7 +24,7 @@ class Ppl::Command::Add < Ppl::Application::Command
22
24
 
23
25
  contact = Ppl::Entity::Contact.new
24
26
  contact.id = contact_id.dup
25
- contact.name = contact_name.dup
27
+ contact.name = @name_service.parse contact_name.dup
26
28
 
27
29
  @storage.save_contact(contact)
28
30
  return true
@@ -53,9 +53,9 @@ class Ppl::Command::Mutt < Ppl::Application::Command
53
53
 
54
54
  def match_by_name(contact, query)
55
55
  if @options[:ignore_case]
56
- contact.name.downcase.include? query.downcase
56
+ contact.name.full.downcase.include? query.downcase
57
57
  else
58
- contact.name.include? query
58
+ contact.name.full.include? query
59
59
  end
60
60
  end
61
61
 
@@ -6,9 +6,25 @@ class Ppl::Command::Name < Ppl::Application::Command
6
6
 
7
7
  attr_writer :show_format
8
8
  attr_writer :list_format
9
+ attr_writer :name_service
9
10
 
10
11
  def options(parser, options)
11
12
  parser.banner = "usage: ppl name <contact> [<name>]"
13
+ parser.on("-f", "--family <family-name(s)>") do |family|
14
+ options[:family] = family
15
+ end
16
+ parser.on("-g", "--given <given-name(s)>") do |given|
17
+ options[:given] = given
18
+ end
19
+ parser.on("-m", "--middle <middle-name(s)>") do |middle|
20
+ options[:middle] = middle
21
+ end
22
+ parser.on("-p", "--prefix <prefix>") do |prefix|
23
+ options[:prefix] = prefix
24
+ end
25
+ parser.on("-s", "--suffix <suffix>") do |suffix|
26
+ options[:suffix] = suffix
27
+ end
12
28
  end
13
29
 
14
30
  def execute(input, output)
@@ -21,7 +37,7 @@ class Ppl::Command::Name < Ppl::Application::Command
21
37
  def determine_action(input)
22
38
  if input.arguments[0].nil?
23
39
  :list_names
24
- elsif input.arguments[1].nil?
40
+ elsif input.arguments[1].nil? && input.options.empty?
25
41
  :show_name
26
42
  else
27
43
  :set_name
@@ -36,7 +52,7 @@ class Ppl::Command::Name < Ppl::Application::Command
36
52
 
37
53
  def show_name(input, output)
38
54
  contact = @storage.require_contact(input.arguments[0])
39
- name = @show_format.process(contact)
55
+ name = @show_format.process(contact.name)
40
56
  if name != ""
41
57
  output.line(name)
42
58
  true
@@ -47,7 +63,11 @@ class Ppl::Command::Name < Ppl::Application::Command
47
63
 
48
64
  def set_name(input, output)
49
65
  contact = @storage.require_contact(input.arguments[0])
50
- contact.name = input.arguments[1].dup
66
+ options = input.options.dup
67
+ if !input.arguments[1].nil?
68
+ options[:full] = input.arguments[1].dup
69
+ end
70
+ @name_service.update(contact.name, options)
51
71
  @storage.save_contact(contact)
52
72
  end
53
73
 
@@ -0,0 +1,14 @@
1
+
2
+ class Ppl::Entity::Name
3
+ attr_accessor :full
4
+ attr_accessor :family
5
+ attr_accessor :given
6
+ attr_accessor :middle
7
+ attr_accessor :prefix
8
+ attr_accessor :suffix
9
+
10
+ def to_s
11
+ @full
12
+ end
13
+ end
14
+
@@ -39,7 +39,7 @@ class Ppl::Format::Contact::Full < Ppl::Format::Contact
39
39
  def first_line(contact)
40
40
  line = ""
41
41
  if !contact.name.nil?
42
- line += contact.name
42
+ line += contact.name.full
43
43
  end
44
44
  email_address = choose_first_line_address(contact)
45
45
  unless email_address.nil?
@@ -0,0 +1,7 @@
1
+
2
+ class Ppl::Format::Name
3
+ def process(name)
4
+ raise NotImplementedError
5
+ end
6
+ end
7
+
@@ -1,5 +1,5 @@
1
1
 
2
- class Ppl::Format::Contact::Name < Ppl::Format::Contact
2
+ class Ppl::Format::Name::FullOnly < Ppl::Format::Name
3
3
 
4
4
  attr_writer :color_adapter
5
5
  attr_writer :colors
@@ -9,10 +9,10 @@ class Ppl::Format::Contact::Name < Ppl::Format::Contact
9
9
  @color_adapter = Ppl::Adapter::Color::Colored.new
10
10
  end
11
11
 
12
- def process(contact)
12
+ def process(name)
13
13
  output = ""
14
- if !contact.name.nil?
15
- output += contact.name
14
+ if !name.full.nil?
15
+ output += name.full
16
16
  end
17
17
  colorize_output(output)
18
18
  end
@@ -0,0 +1,23 @@
1
+
2
+ class Ppl::Service::Name
3
+
4
+ def parse(full_name)
5
+ parts = full_name.split " "
6
+ name = Ppl::Entity::Name.new
7
+ name.full = full_name
8
+ name.given = parts.shift unless parts[0].nil?
9
+ name.family = parts.join(" ") unless parts[0].nil?
10
+ name
11
+ end
12
+
13
+ def update(name, new_values)
14
+ [:full, :given, :family, :middle, :prefix, :suffix].each do |property_name|
15
+ if !new_values[property_name].nil?
16
+ setter = (property_name.to_s + "=").to_sym
17
+ name.send(setter, new_values[property_name])
18
+ end
19
+ end
20
+ end
21
+
22
+ end
23
+
data/ppl.gemspec CHANGED
@@ -2,8 +2,8 @@
2
2
  Gem::Specification.new do |spec|
3
3
 
4
4
  spec.name = "ppl"
5
- spec.version = "2.0.0"
6
- spec.date = "2013-05-09"
5
+ spec.version = "2.1.0"
6
+ spec.date = "2013-07-20"
7
7
 
8
8
  spec.required_ruby_version = ">= 1.9.3"
9
9
 
@@ -5,6 +5,7 @@ describe Ppl::Adapter::Vcard::GreenCard, "#encode" do
5
5
  before(:each) do
6
6
  @adapter = Ppl::Adapter::Vcard::GreenCard.new
7
7
  @contact = Ppl::Entity::Contact.new
8
+ @contact.name = Ppl::Entity::Name.new
8
9
  @contact.id = "test"
9
10
  end
10
11
 
@@ -13,11 +14,36 @@ describe Ppl::Adapter::Vcard::GreenCard, "#encode" do
13
14
  @adapter.encode(@contact).should include("BDAY:20000101")
14
15
  end
15
16
 
16
- it "should encode the contact's name" do
17
- @contact.name = "John Doe"
17
+ it "should encode the contact's full name" do
18
+ @contact.name.full = "John Doe"
18
19
  @adapter.encode(@contact).should include("FN:John Doe")
19
20
  end
20
21
 
22
+ it "should encode the contact's given name" do
23
+ @contact.name.given = "John"
24
+ @adapter.encode(@contact).should include("N:;John;;;")
25
+ end
26
+
27
+ it "should encode the contact's family name" do
28
+ @contact.name.family = "Smith"
29
+ @adapter.encode(@contact).should include("N:Smith;;;;")
30
+ end
31
+
32
+ it "should encode the contact's middle name" do
33
+ @contact.name.middle = "Quentin"
34
+ @adapter.encode(@contact).should include("N:;;Quentin;;")
35
+ end
36
+
37
+ it "should encode the contact's name prefix" do
38
+ @contact.name.prefix = "Mr."
39
+ @adapter.encode(@contact).should include("N:;;;Mr.;")
40
+ end
41
+
42
+ it "should encode the contact's name suffix" do
43
+ @contact.name.suffix = "BSc"
44
+ @adapter.encode(@contact).should include("N:;;;;BSc")
45
+ end
46
+
21
47
  it "should encode the contact's email address" do
22
48
  @contact.email_addresses << Ppl::Entity::EmailAddress.new("john@example.org")
23
49
  @adapter.encode(@contact).should include("EMAIL:john@example.org")
@@ -151,7 +177,7 @@ describe Ppl::Adapter::Vcard::GreenCard, "#decode" do
151
177
  ].join("\n")
152
178
  contact = @adapter.decode(vcard)
153
179
 
154
- contact.name.should eq "John Doe"
180
+ contact.name.full.should eq "John Doe"
155
181
  end
156
182
 
157
183
  it "should decode the contact's email address" do
@@ -387,7 +413,7 @@ describe Ppl::Adapter::Vcard::GreenCard, "#decode" do
387
413
  "END:VCARD",
388
414
  ].join("\n")
389
415
  contact = @adapter.decode(vcard)
390
- contact.name.should eq "Straße"
416
+ contact.name.full.should eq "Straße"
391
417
  end
392
418
 
393
419
  end
@@ -336,16 +336,16 @@ describe Ppl::Application::Bootstrap do
336
336
  end
337
337
  end
338
338
 
339
- describe "#format_contact_name" do
339
+ describe "#format_name_full_only" do
340
340
  it "should return a Ppl::Format::Contact::Name" do
341
- @bootstrap.format_contact_name.should be_a(Ppl::Format::Contact::Name)
341
+ @bootstrap.format_name_full_only.should be_a(Ppl::Format::Name::FullOnly)
342
342
  end
343
343
  it "should set up colored output if configured to do so" do
344
344
  @colors = {}
345
345
  @config = double(Ppl::Application::Configuration)
346
346
  @bootstrap.stub(:configuration).and_return(@config)
347
347
  @config.should_receive(:command_colors).with("name").and_return(@colors)
348
- @bootstrap.format_contact_name
348
+ @bootstrap.format_name_full_only
349
349
  end
350
350
  end
351
351
 
@@ -559,6 +559,12 @@ describe Ppl::Application::Bootstrap do
559
559
  end
560
560
  end
561
561
 
562
+ describe "#name_service" do
563
+ it "should return a Ppl::Service::Name" do
564
+ @bootstrap.name_service.should be_a(Ppl::Service::Name)
565
+ end
566
+ end
567
+
562
568
  describe "#postal_address_service" do
563
569
  it "should return a Ppl::Service::PostalAddress" do
564
570
  @bootstrap.postal_address_service.should be_a(Ppl::Service::PostalAddress)
@@ -5,8 +5,10 @@ describe Ppl::Command::Add do
5
5
  @command = Ppl::Command::Add.new
6
6
  @input = Ppl::Application::Input.new
7
7
  @storage = double(Ppl::Adapter::Storage)
8
+ @name_service = double(Ppl::Service::Name)
8
9
 
9
10
  @command.storage = @storage
11
+ @command.name_service = @name_service
10
12
  end
11
13
 
12
14
  describe "#name" do
@@ -29,8 +31,12 @@ describe Ppl::Command::Add do
29
31
  it "should save a new contact" do
30
32
  @storage.should_receive(:save_contact) do |contact|
31
33
  contact.id.should eq "john"
32
- contact.name.should eq "John Doe"
34
+ contact.name.should be_a(Ppl::Entity::Name)
33
35
  end
36
+ @name_service
37
+ .should_receive(:parse)
38
+ .with("John Doe")
39
+ .and_return(Ppl::Entity::Name.new)
34
40
  @input.arguments = ["john", "John Doe"]
35
41
  @command.execute(@input, nil)
36
42
  end
@@ -10,6 +10,7 @@ describe Ppl::Command::Mutt do
10
10
 
11
11
  @address_book = Ppl::Entity::AddressBook.new
12
12
  @contact = Ppl::Entity::Contact.new
13
+ @contact.name = Ppl::Entity::Name.new
13
14
 
14
15
  @command.storage = @storage
15
16
  @command.format = @format
@@ -36,7 +37,7 @@ describe Ppl::Command::Mutt do
36
37
 
37
38
  it "should return email address matches" do
38
39
 
39
- @contact.name = "Test User"
40
+ @contact.name.full = "Test User"
40
41
  @contact.email_addresses << Ppl::Entity::EmailAddress.new("test@example.org")
41
42
  @address_book.contacts.push(@contact)
42
43
 
@@ -53,7 +54,7 @@ describe Ppl::Command::Mutt do
53
54
 
54
55
  it "should only return matching email addresses" do
55
56
  @input.arguments.push "prova"
56
- @contact.name = "Test User"
57
+ @contact.name.full = "Test User"
57
58
 
58
59
  @contact.email_addresses << Ppl::Entity::EmailAddress.new("test@test.org")
59
60
  @contact.email_addresses << Ppl::Entity::EmailAddress.new("prova@prova.org")
@@ -69,7 +70,7 @@ describe Ppl::Command::Mutt do
69
70
 
70
71
  it "should return name matches" do
71
72
 
72
- @contact.name = "Test User"
73
+ @contact.name.full = "Test User"
73
74
  @contact.email_addresses << Ppl::Entity::EmailAddress.new("test@example.org")
74
75
  @address_book.contacts.push(@contact)
75
76
 
@@ -88,7 +89,7 @@ describe Ppl::Command::Mutt do
88
89
  it "should count up email addresses in the status line" do
89
90
  @input.arguments.push "org"
90
91
 
91
- @contact.name = "Test User"
92
+ @contact.name.full = "Test User"
92
93
  @contact.email_addresses << Ppl::Entity::EmailAddress.new("test@test.org")
93
94
  @contact.email_addresses << Ppl::Entity::EmailAddress.new("prova@prova.org")
94
95
  @address_book.contacts << @contact
@@ -108,7 +109,7 @@ describe Ppl::Command::Mutt do
108
109
 
109
110
  before(:each) do
110
111
  @input.options[:ignore_case] = true
111
- @contact.name = "Joe Schmoe"
112
+ @contact.name.full = "Joe Schmoe"
112
113
  @contact.email_addresses << Ppl::Entity::EmailAddress.new("joe@somewhere.com")
113
114
  @contact.email_addresses << Ppl::Entity::EmailAddress.new("LOUD@SHOUTING.COM")
114
115
  @address_book.contacts << @contact
@@ -9,15 +9,18 @@ describe Ppl::Command::Name do
9
9
 
10
10
  @address_book = Ppl::Entity::AddressBook.new
11
11
 
12
- @storage = double(Ppl::Adapter::Storage)
13
- @show_format = double(Ppl::Format::Contact)
14
- @list_format = double(Ppl::Format::Contact)
12
+ @storage = double(Ppl::Adapter::Storage)
13
+ @show_format = double(Ppl::Format::Contact)
14
+ @list_format = double(Ppl::Format::Contact)
15
+ @name_service = double(Ppl::Service::Name)
15
16
 
16
- @command.storage = @storage
17
- @command.show_format = @show_format
18
- @command.list_format = @list_format
17
+ @command.storage = @storage
18
+ @command.show_format = @show_format
19
+ @command.list_format = @list_format
20
+ @command.name_service = @name_service
19
21
 
20
22
  @contact.id = "jim"
23
+ @contact.name = Ppl::Entity::Name.new
21
24
  end
22
25
 
23
26
  describe "#name" do
@@ -53,13 +56,25 @@ describe Ppl::Command::Name do
53
56
 
54
57
  it "should change the contact's name if a name is given" do
55
58
  @storage.should_receive(:require_contact).and_return(@contact)
56
- @storage.should_receive(:save_contact) do |contact|
57
- contact.name.should eq "Jim Jamieson"
58
- end
59
+ @name_service.should_receive(:update).with(@contact.name, {
60
+ :full => "Jim Jamieson"
61
+ })
62
+ @storage.should_receive(:save_contact)
59
63
  @input.arguments = ["jim", "Jim Jamieson"]
60
64
  @command.execute(@input, @output)
61
65
  end
62
66
 
67
+ it "should change the contact's name if a name is given" do
68
+ @storage.should_receive(:require_contact).and_return(@contact)
69
+ @name_service.should_receive(:update).with(@contact.name, {
70
+ :family => "Smith"
71
+ })
72
+ @storage.should_receive(:save_contact)
73
+ @input.arguments = ["jim"]
74
+ @input.options = { :family => "Smith" }
75
+ @command.execute(@input, @output)
76
+ end
77
+
63
78
  end
64
79
 
65
80
  end
@@ -0,0 +1,16 @@
1
+
2
+ describe Ppl::Entity::Name do
3
+
4
+ before(:each) do
5
+ @name = Ppl::Entity::Name.new
6
+ end
7
+
8
+ describe "#to_s" do
9
+ it "returns the full name" do
10
+ @name.full = "Mr. Testing"
11
+ @name.to_s.should eq "Mr. Testing"
12
+ end
13
+ end
14
+
15
+ end
16
+
@@ -23,18 +23,21 @@ describe Ppl::Format::Contact::Full do
23
23
  end
24
24
 
25
25
  it "should start with the contact's name" do
26
- @contact.name = "John Doe"
26
+ @contact.name = Ppl::Entity::Name.new
27
+ @contact.name.full = "John Doe"
27
28
  @format.process(@contact).should eq "John Doe"
28
29
  end
29
30
 
30
31
  it "should include their email address in brackets" do
31
- @contact.name = "John Doe"
32
+ @contact.name = Ppl::Entity::Name.new
33
+ @contact.name.full = "John Doe"
32
34
  @contact.email_addresses << Ppl::Entity::EmailAddress.new("john@example.org")
33
35
  @format.process(@contact).should include "John Doe <john@example.org>"
34
36
  end
35
37
 
36
38
  it "should include their preferred email address in brackets" do
37
- @contact.name = "John Doe"
39
+ @contact.name = Ppl::Entity::Name.new
40
+ @contact.name.full = "John Doe"
38
41
  @contact.email_addresses << Ppl::Entity::EmailAddress.new("john@example.org")
39
42
  @contact.email_addresses << Ppl::Entity::EmailAddress.new("fred@testtest.es")
40
43
  @contact.email_addresses[1].preferred = true
@@ -0,0 +1,31 @@
1
+
2
+ describe Ppl::Format::Name::FullOnly do
3
+
4
+ before(:each) do
5
+ @format = Ppl::Format::Name::FullOnly.new
6
+ @name = Ppl::Entity::Name.new
7
+ @color = double(Ppl::Adapter::Color)
8
+ @format.color_adapter = @color
9
+ end
10
+
11
+ describe "#process" do
12
+
13
+ it "should return an empty string if the contact lacks a name" do
14
+ @format.process(@name).should eq ""
15
+ end
16
+
17
+ it "should return just the full name" do
18
+ @name.full = "John Doe"
19
+ @format.process(@name).should eq "John Doe"
20
+ end
21
+
22
+ it "should colorize the string if configured to do so" do
23
+ @format.colors = { "name" => "blue" }
24
+ @color.should_receive(:colorize).and_return("name in blue")
25
+ @format.process(@name).should eq "name in blue"
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+
@@ -0,0 +1,18 @@
1
+
2
+ describe Ppl::Format::Name do
3
+
4
+ before(:each) do
5
+ @format = Ppl::Format::Name.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
+
@@ -0,0 +1,60 @@
1
+
2
+ describe Ppl::Service::Name do
3
+
4
+ before(:each) do
5
+ @service = Ppl::Service::Name.new
6
+ @name = Ppl::Entity::Name.new
7
+ end
8
+
9
+ describe "#parse" do
10
+
11
+ it "uses the whole string for the full name" do
12
+ @service.parse("John Smith").full.should eq "John Smith"
13
+ end
14
+
15
+ it "uses the first word for the given name" do
16
+ @service.parse("John Smith").given.should eq "John"
17
+ end
18
+
19
+ it "uses the rest of the string for the family names" do
20
+ @service.parse("John Fitzgerald Donald Smith").family.should eq "Fitzgerald Donald Smith"
21
+ end
22
+
23
+ end
24
+
25
+ describe "#update" do
26
+
27
+ it "updates the full name" do
28
+ @service.update(@name, {:full => "Abc Def"})
29
+ @name.full.should eq "Abc Def"
30
+ end
31
+
32
+ it "updates the given names" do
33
+ @service.update(@name, {:given => "John"})
34
+ @name.given.should eq "John"
35
+ end
36
+
37
+ it "updates the family names" do
38
+ @service.update(@name, {:family => "Smith"})
39
+ @name.family.should eq "Smith"
40
+ end
41
+
42
+ it "updates the middle names" do
43
+ @service.update(@name, {:middle => "Arnold"})
44
+ @name.middle.should eq "Arnold"
45
+ end
46
+
47
+ it "updates the name prefix" do
48
+ @service.update(@name, {:prefix => "Mr"})
49
+ @name.prefix.should eq "Mr"
50
+ end
51
+
52
+ it "updates the name suffix" do
53
+ @service.update(@name, {:suffix => "BSc"})
54
+ @name.suffix.should eq "BSc"
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ppl
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henry Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-09 00:00:00.000000000 Z
11
+ date: 2013-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored
@@ -229,6 +229,7 @@ files:
229
229
  - lib/ppl/entity/address_book.rb
230
230
  - lib/ppl/entity/contact.rb
231
231
  - lib/ppl/entity/email_address.rb
232
+ - lib/ppl/entity/name.rb
232
233
  - lib/ppl/entity/phone_number.rb
233
234
  - lib/ppl/entity/postal_address.rb
234
235
  - lib/ppl/error/completion_not_found.rb
@@ -252,7 +253,6 @@ files:
252
253
  - lib/ppl/format/contact/birthday.rb
253
254
  - lib/ppl/format/contact/email_addresses.rb
254
255
  - lib/ppl/format/contact/full.rb
255
- - lib/ppl/format/contact/name.rb
256
256
  - lib/ppl/format/contact/nicknames.rb
257
257
  - lib/ppl/format/contact/organization.rb
258
258
  - lib/ppl/format/contact/phone_number.rb
@@ -263,11 +263,14 @@ files:
263
263
  - lib/ppl/format/custom/contact.rb
264
264
  - lib/ppl/format/custom/email_address.rb
265
265
  - lib/ppl/format/custom/phone_number.rb
266
+ - lib/ppl/format/name.rb
267
+ - lib/ppl/format/name/full_only.rb
266
268
  - lib/ppl/format/postal_address.rb
267
269
  - lib/ppl/format/postal_address/multi_line.rb
268
270
  - lib/ppl/format/postal_address/one_line.rb
269
271
  - lib/ppl/format/table.rb
270
272
  - lib/ppl/service/email_address.rb
273
+ - lib/ppl/service/name.rb
271
274
  - lib/ppl/service/phone_number.rb
272
275
  - lib/ppl/service/postal_address.rb
273
276
  - ppl.gemspec
@@ -315,6 +318,7 @@ files:
315
318
  - spec/ppl/entity/address_book_spec.rb
316
319
  - spec/ppl/entity/contact_spec.rb
317
320
  - spec/ppl/entity/email_address_spec.rb
321
+ - spec/ppl/entity/name_spec.rb
318
322
  - spec/ppl/entity/phone_number_spec.rb
319
323
  - spec/ppl/entity/postal_address_spec.rb
320
324
  - spec/ppl/format/address_book/ages_spec.rb
@@ -333,7 +337,6 @@ files:
333
337
  - spec/ppl/format/contact/birthday_spec.rb
334
338
  - spec/ppl/format/contact/email_addresses_spec.rb
335
339
  - spec/ppl/format/contact/full_spec.rb
336
- - spec/ppl/format/contact/name_spec.rb
337
340
  - spec/ppl/format/contact/nicknames_spec.rb
338
341
  - spec/ppl/format/contact/organization_spec.rb
339
342
  - spec/ppl/format/contact/phone_number_spec.rb
@@ -345,11 +348,14 @@ files:
345
348
  - spec/ppl/format/custom/email_address_spec.rb
346
349
  - spec/ppl/format/custom/phone_number_spec.rb
347
350
  - spec/ppl/format/custom_spec.rb
351
+ - spec/ppl/format/name/full_only_spec.rb
352
+ - spec/ppl/format/name_spec.rb
348
353
  - spec/ppl/format/postal_address/multi_line_spec.rb
349
354
  - spec/ppl/format/postal_address/one_line_spec.rb
350
355
  - spec/ppl/format/postal_address_spec.rb
351
356
  - spec/ppl/format/table_spec.rb
352
357
  - spec/ppl/service/email_address_spec.rb
358
+ - spec/ppl/service/name_spec.rb
353
359
  - spec/ppl/service/phone_number_spec.rb
354
360
  - spec/ppl/service/postal_address_spec.rb
355
361
  - spec/spec_helper.rb
@@ -1,31 +0,0 @@
1
-
2
- describe Ppl::Format::Contact::Name do
3
-
4
- before(:each) do
5
- @format = Ppl::Format::Contact::Name.new
6
- @contact = Ppl::Entity::Contact.new
7
- @color = double(Ppl::Adapter::Color)
8
- @format.color_adapter = @color
9
- end
10
-
11
- describe "#process" do
12
-
13
- it "should return an empty string if the contact lacks a name" do
14
- @format.process(Ppl::Entity::Contact.new).should eq ""
15
- end
16
-
17
- it "should return the contact's name if it is set" do
18
- @contact.name = "John Doe"
19
- @format.process(@contact).should eq "John Doe"
20
- end
21
-
22
- it "should colorize the string if configured to do so" do
23
- @format.colors = { "name" => "blue" }
24
- @color.should_receive(:colorize).and_return("name in blue")
25
- @format.process(@contact).should eq "name in blue"
26
- end
27
-
28
- end
29
-
30
- end
31
-