ppl 1.3.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/ppl.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Ppl
3
3
 
4
- Version = "1.3.0"
4
+ Version = "1.4.1"
5
5
 
6
6
  module Adapter
7
7
  end
@@ -73,7 +73,7 @@ require "ppl/format/address_book/phone_numbers"
73
73
  require "ppl/format/address_book/postal_addresses"
74
74
  require "ppl/format/contact"
75
75
  require "ppl/format/contact/birthday"
76
- require "ppl/format/contact/email_address"
76
+ require "ppl/format/contact/email_addresses"
77
77
  require "ppl/format/contact/full"
78
78
  require "ppl/format/contact/name"
79
79
  require "ppl/format/contact/organization"
@@ -15,8 +15,8 @@ class Ppl::Adapter::Vcard::Vpim
15
15
  name.fullname = contact.name unless contact.name.nil?
16
16
  end
17
17
 
18
- if !contact.email_address.nil?
19
- maker.add_email(contact.email_address)
18
+ contact.email_addresses.each do |email_address|
19
+ maker.add_email(email_address)
20
20
  end
21
21
 
22
22
  if !contact.phone_number.nil?
@@ -64,7 +64,7 @@ class Ppl::Adapter::Vcard::Vpim
64
64
  end
65
65
 
66
66
  vcard.emails.each do |email|
67
- contact.email_address = email.to_s
67
+ contact.email_addresses.push(email.to_s)
68
68
  end
69
69
 
70
70
  if !vcard.telephones.empty?
@@ -7,7 +7,7 @@ class Ppl::Command::Email < Ppl::Application::Command
7
7
  def initialize
8
8
  @name = "email"
9
9
  @description = "Show or change a contact's email address"
10
- @show_format = Ppl::Format::Contact::EmailAddress.new
10
+ @show_format = Ppl::Format::Contact::EmailAddresses.new
11
11
  @list_format = Ppl::Format::AddressBook::EmailAddresses.new
12
12
  end
13
13
 
@@ -27,7 +27,7 @@ class Ppl::Command::Email < Ppl::Application::Command
27
27
  if input.arguments[0].nil?
28
28
  :list_email_addresses
29
29
  elsif input.arguments[1].nil?
30
- :show_email_address
30
+ :show_email_addresses
31
31
  else
32
32
  :set_email_address
33
33
  end
@@ -39,7 +39,7 @@ class Ppl::Command::Email < Ppl::Application::Command
39
39
  output.line(email_list)
40
40
  end
41
41
 
42
- def show_email_address(input, output)
42
+ def show_email_addresses(input, output)
43
43
  contact = @storage.require_contact(input.arguments[0])
44
44
  email_address = @show_format.process(contact)
45
45
  if email_address != ""
@@ -52,7 +52,14 @@ class Ppl::Command::Email < Ppl::Application::Command
52
52
 
53
53
  def set_email_address(input, output)
54
54
  contact = @storage.require_contact(input.arguments[0])
55
- contact.email_address = input.arguments[1].dup
55
+ email_address = input.arguments[1].dup
56
+
57
+ if contact.has_email_address?(email_address)
58
+ message = sprintf("%s already has email address %s", contact.id, email_address)
59
+ raise Ppl::Error::IncorrectUsage, message
60
+ else
61
+ contact.email_addresses.push(email_address)
62
+ end
56
63
  @storage.save_contact(contact)
57
64
  end
58
65
 
@@ -52,9 +52,13 @@ class Ppl::Command::Mutt < Ppl::Application::Command
52
52
  matches = Ppl::Entity::AddressBook.new
53
53
 
54
54
  address_book.each do |contact|
55
- next if contact.email_address.nil?
55
+ next if contact.email_addresses.empty?
56
56
 
57
- if contact.email_address.include?(query)
57
+ matching_emails = contact.email_addresses.select do |email_address|
58
+ email_address.include? query
59
+ end
60
+
61
+ if matching_emails.length > 0
58
62
  matches.add_contact(contact)
59
63
  elsif !contact.name.nil? && contact.name.include?(query)
60
64
  matches.add_contact(contact)
@@ -3,12 +3,16 @@ class Ppl::Entity::Contact
3
3
 
4
4
  attr_accessor :id
5
5
  attr_accessor :name
6
- attr_accessor :email_address
6
+ attr_accessor :email_addresses
7
7
  attr_accessor :birthday
8
8
  attr_accessor :phone_number
9
9
  attr_accessor :organization
10
10
  attr_accessor :postal_address
11
11
 
12
+ def initialize
13
+ @email_addresses = []
14
+ end
15
+
12
16
  def set_postal_address
13
17
  if @postal_address.nil?
14
18
  @postal_address = Ppl::Entity::PostalAddress.new
@@ -16,5 +20,9 @@ class Ppl::Entity::Contact
16
20
  yield @postal_address
17
21
  end
18
22
 
23
+ def has_email_address?(email_address)
24
+ @email_addresses.include? email_address
25
+ end
26
+
19
27
  end
20
28
 
@@ -4,7 +4,7 @@ class Ppl::Format::AddressBook::EmailAddresses < Ppl::Format::AddressBook
4
4
  attr_writer :table
5
5
 
6
6
  def initialize
7
- @table = Ppl::Format::Table.new([:id, :email_address])
7
+ @table = Ppl::Format::Table.new([:id, :email_addresses])
8
8
  end
9
9
 
10
10
  def process(address_book)
@@ -16,16 +16,16 @@ class Ppl::Format::AddressBook::EmailAddresses < Ppl::Format::AddressBook
16
16
  private
17
17
 
18
18
  def add_row(contact)
19
- id = sprintf("%s:", contact.id)
20
- email_address = nil
19
+ id = sprintf("%s:", contact.id)
20
+ email_addresses = nil
21
21
 
22
- if !contact.email_address.nil?
23
- email_address = contact.email_address
22
+ if !contact.email_addresses.empty?
23
+ email_addresses = contact.email_addresses.join(", ")
24
24
  end
25
25
 
26
26
  @table.add_row({
27
27
  :id => id,
28
- :email_address => email_address,
28
+ :email_addresses => email_addresses,
29
29
  })
30
30
  end
31
31
 
@@ -23,7 +23,7 @@ class Ppl::Format::AddressBook::MuttQuery < Ppl::Format::AddressBook
23
23
  end
24
24
 
25
25
  @table.add_row({
26
- :email => contact.email_address,
26
+ :email => contact.email_addresses.first,
27
27
  :name => name,
28
28
  })
29
29
  end
@@ -19,8 +19,8 @@ class Ppl::Format::AddressBook::OneLine < Ppl::Format::AddressBook
19
19
  name = contact.name
20
20
  email = nil
21
21
 
22
- if !contact.email_address.nil?
23
- email = sprintf("<%s>", contact.email_address)
22
+ if !contact.email_addresses.empty?
23
+ email = sprintf("<%s>", contact.email_addresses.first)
24
24
  end
25
25
 
26
26
  @table.add_row({
@@ -0,0 +1,13 @@
1
+
2
+ class Ppl::Format::Contact::EmailAddresses < Ppl::Format::Contact
3
+
4
+ def process(contact)
5
+ lines = []
6
+ contact.email_addresses.each do |email_address|
7
+ lines.push email_address
8
+ end
9
+ lines.join("\n")
10
+ end
11
+
12
+ end
13
+
@@ -38,8 +38,8 @@ class Ppl::Format::Contact::Full < Ppl::Format::Contact
38
38
  if !contact.name.nil?
39
39
  line += contact.name
40
40
  end
41
- if !contact.email_address.nil?
42
- line += " <#{contact.email_address}>"
41
+ if !contact.email_addresses.empty?
42
+ line += " <#{contact.email_addresses.first}>"
43
43
  end
44
44
  return line
45
45
  end
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |spec|
3
3
 
4
4
  spec.name = "ppl"
5
- spec.version = "1.3.0"
5
+ spec.version = "1.4.1"
6
6
  spec.date = "2012-12-20"
7
7
 
8
8
  spec.required_ruby_version = ">= 1.9.3"
@@ -18,7 +18,7 @@ describe Ppl::Adapter::Vcard::Vpim, "#encode" do
18
18
  end
19
19
 
20
20
  it "should encode the contact's email address" do
21
- @contact.email_address = "john@example.org"
21
+ @contact.email_addresses = ["john@example.org"]
22
22
  @adapter.encode(@contact).should include("EMAIL:john@example.org")
23
23
  end
24
24
 
@@ -121,7 +121,7 @@ describe Ppl::Adapter::Vcard::Vpim, "#decode" do
121
121
  "END:VCARD",
122
122
  ].join("\n")
123
123
  contact = @adapter.decode(vcard)
124
- contact.email_address.should eq "home@example.org"
124
+ contact.email_addresses.first.should eq "home@example.org"
125
125
  end
126
126
 
127
127
  it "should decode the contact's phone number" do
@@ -48,15 +48,22 @@ describe Ppl::Command::Email do
48
48
  @command.execute(@input, @output).should eq false
49
49
  end
50
50
 
51
- it "should change the contact's email address if an address is given" do
51
+ it "should add the given address to the contact if it's new" do
52
52
  @storage.should_receive(:require_contact).and_return(@contact)
53
53
  @storage.should_receive(:save_contact) do |contact|
54
- contact.email_address.should eq "jim@example.org"
54
+ contact.email_addresses.first.should eq "jim@example.org"
55
55
  end
56
56
  @input.arguments = ["jim", "jim@example.org"]
57
57
  @command.execute(@input, @output)
58
58
  end
59
59
 
60
+ it "should raise an error if the user is adding a duplicate address" do
61
+ @contact.email_addresses.push "jim@example.org"
62
+ @storage.should_receive(:require_contact).and_return(@contact)
63
+ @input.arguments = ["jim", "jim@example.org"]
64
+ expect{@command.execute(@input, nil)}.to raise_error(Ppl::Error::IncorrectUsage)
65
+ end
66
+
60
67
  end
61
68
 
62
69
  end
@@ -36,7 +36,7 @@ describe Ppl::Command::Mutt do
36
36
  it "should return email address matches" do
37
37
 
38
38
  @contact.name = "Test User"
39
- @contact.email_address = "test@example.org"
39
+ @contact.email_addresses.push "test@example.org"
40
40
  @address_book.add_contact(@contact)
41
41
 
42
42
  @input.arguments.push "example"
@@ -50,7 +50,7 @@ describe Ppl::Command::Mutt do
50
50
  it "should return name matches" do
51
51
 
52
52
  @contact.name = "Test User"
53
- @contact.email_address = "test@example.org"
53
+ @contact.email_addresses.push "test@example.org"
54
54
  @address_book.add_contact(@contact)
55
55
 
56
56
  @input.arguments.push "User"
@@ -18,9 +18,9 @@ describe Ppl::Entity::Contact do
18
18
  end
19
19
  end
20
20
 
21
- describe "#email_address" do
22
- it "should return a value" do
23
- @contact.email_address.should eq nil
21
+ describe "#email_addresses" do
22
+ it "should return an array" do
23
+ @contact.email_addresses.should be_a(Array)
24
24
  end
25
25
  end
26
26
 
@@ -36,5 +36,15 @@ describe Ppl::Entity::Contact do
36
36
  end
37
37
  end
38
38
 
39
+ describe "#has_email_address?" do
40
+ it "should know if the contact has the given email address" do
41
+ @contact.email_addresses.push "test@example.org"
42
+ @contact.has_email_address?("test@example.org").should eq true
43
+ end
44
+ it "should know if the contact lacks the given email address" do
45
+ @contact.has_email_address?("test@example.org").should eq false
46
+ end
47
+ end
48
+
39
49
  end
40
50
 
@@ -17,17 +17,17 @@ describe Ppl::Format::AddressBook::EmailAddresses do
17
17
 
18
18
  it "should at least show the contact's id" do
19
19
  @table.should_receive(:add_row).with({
20
- :id => "test:",
21
- :email_address => nil,
20
+ :id => "test:",
21
+ :email_addresses => nil,
22
22
  })
23
23
  @format.process(@address_book)
24
24
  end
25
25
 
26
- it "should show the email address if it's available" do
27
- @contact.email_address = "jdoe@example.org"
26
+ it "should show an email address if it's available" do
27
+ @contact.email_addresses.push "jdoe@example.org"
28
28
  @table.should_receive(:add_row).with({
29
- :id => "test:",
30
- :email_address => "jdoe@example.org",
29
+ :id => "test:",
30
+ :email_addresses => "jdoe@example.org",
31
31
  })
32
32
  @format.process(@address_book)
33
33
  end
@@ -7,8 +7,8 @@ describe Ppl::Format::AddressBook::MuttQuery do
7
7
  @contact = Ppl::Entity::Contact.new
8
8
  @table = double(Ppl::Format::Table)
9
9
 
10
- @contact.email_address = "test@example.org"
11
- @contact.name = "Test Contact"
10
+ @contact.email_addresses.push "test@example.org"
11
+ @contact.name = "Test Contact"
12
12
 
13
13
  @format.table = @table
14
14
  @address_book.add_contact(@contact)
@@ -26,7 +26,7 @@ describe Ppl::Format::AddressBook::OneLine do
26
26
 
27
27
  it "should show all the info if it's available" do
28
28
  @contact.name = "John Doe"
29
- @contact.email_address = "jdoe@example.org"
29
+ @contact.email_addresses.push "jdoe@example.org"
30
30
  @table.should_receive(:add_row).with({
31
31
  :id => "test:",
32
32
  :name => "John Doe",
@@ -1,8 +1,8 @@
1
1
 
2
- describe Ppl::Format::Contact::EmailAddress do
2
+ describe Ppl::Format::Contact::EmailAddresses do
3
3
 
4
4
  before(:each) do
5
- @format = Ppl::Format::Contact::EmailAddress.new
5
+ @format = Ppl::Format::Contact::EmailAddresses.new
6
6
  @contact = Ppl::Entity::Contact.new
7
7
  end
8
8
 
@@ -13,7 +13,7 @@ describe Ppl::Format::Contact::EmailAddress do
13
13
  end
14
14
 
15
15
  it "should return the contact's email address if it is set" do
16
- @contact.email_address = "jdoe@example.org"
16
+ @contact.email_addresses.push "jdoe@example.org"
17
17
  @format.process(@contact).should eq "jdoe@example.org"
18
18
  end
19
19
 
@@ -22,8 +22,8 @@ describe Ppl::Format::Contact::Full do
22
22
  end
23
23
 
24
24
  it "should include their email address in brackets" do
25
- @contact.name = "John Doe"
26
- @contact.email_address = "john@example.org"
25
+ @contact.name = "John Doe"
26
+ @contact.email_addresses.push "john@example.org"
27
27
  @format.process(@contact).should eq "John Doe <john@example.org>"
28
28
  end
29
29
 
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.3.0
4
+ version: 1.4.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: &16554540 !ruby/object:Gem::Requirement
16
+ requirement: &15422560 !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: *16554540
24
+ version_requirements: *15422560
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rugged
27
- requirement: &16542760 !ruby/object:Gem::Requirement
27
+ requirement: &15420820 !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: *16542760
35
+ version_requirements: *15420820
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: vpim
38
- requirement: &16542000 !ruby/object:Gem::Requirement
38
+ requirement: &15420120 !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: *16542000
46
+ version_requirements: *15420120
47
47
  description: CLI Address Book
48
48
  email: henry@henrysmith.org
49
49
  executables:
@@ -104,7 +104,7 @@ files:
104
104
  - lib/ppl/format/address_book/postal_addresses.rb
105
105
  - lib/ppl/format/contact.rb
106
106
  - lib/ppl/format/contact/birthday.rb
107
- - lib/ppl/format/contact/email_address.rb
107
+ - lib/ppl/format/contact/email_addresses.rb
108
108
  - lib/ppl/format/contact/full.rb
109
109
  - lib/ppl/format/contact/name.rb
110
110
  - lib/ppl/format/contact/organization.rb
@@ -153,7 +153,7 @@ files:
153
153
  - spec/ppl/format/address_book/postal_addresses_spec.rb
154
154
  - spec/ppl/format/address_book_spec.rb
155
155
  - spec/ppl/format/contact/birthday_spec.rb
156
- - spec/ppl/format/contact/email_address_spec.rb
156
+ - spec/ppl/format/contact/email_addresses_spec.rb
157
157
  - spec/ppl/format/contact/full_spec.rb
158
158
  - spec/ppl/format/contact/name_spec.rb
159
159
  - spec/ppl/format/contact/organization_spec.rb
@@ -1,13 +0,0 @@
1
-
2
- class Ppl::Format::Contact::EmailAddress < Ppl::Format::Contact
3
-
4
- def process(contact)
5
- output = ""
6
- if !contact.email_address.nil?
7
- output += contact.email_address
8
- end
9
- return output
10
- end
11
-
12
- end
13
-