ppl 1.9.0 → 1.10.0

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.
@@ -17,8 +17,8 @@ class Ppl::Adapter::Vcard::Vpim
17
17
  encode_birthday(contact, maker)
18
18
  encode_name(contact, maker)
19
19
  encode_email_addresses(contact, maker)
20
- encode_phone_number(contact, maker)
21
- encode_organization(contact, maker)
20
+ encode_phone_numbers(contact, maker)
21
+ encode_organizations(contact, maker)
22
22
  encode_postal_address(contact, maker)
23
23
  encode_urls(contact, maker)
24
24
  end
@@ -30,9 +30,9 @@ class Ppl::Adapter::Vcard::Vpim
30
30
  contact = Ppl::Entity::Contact.new
31
31
  decode_birthday(vcard, contact)
32
32
  decode_email_addresses(vcard, contact)
33
- decode_phone_number(vcard, contact)
33
+ decode_phone_numbers(vcard, contact)
34
34
  decode_postal_address(vcard, contact)
35
- decode_organization(vcard, contact)
35
+ decode_organizations(vcard, contact)
36
36
  decode_name(vcard, contact)
37
37
  decode_urls(vcard, contact)
38
38
  return contact
@@ -60,15 +60,15 @@ class Ppl::Adapter::Vcard::Vpim
60
60
  end
61
61
  end
62
62
 
63
- def encode_phone_number(contact, vcard_maker)
64
- if !contact.phone_number.nil?
65
- vcard_maker.add_tel(contact.phone_number)
63
+ def encode_phone_numbers(contact, vcard_maker)
64
+ contact.phone_numbers.each do |phone_number|
65
+ vcard_maker.add_tel(phone_number)
66
66
  end
67
67
  end
68
68
 
69
- def encode_organization(contact, vcard_maker)
70
- if !contact.organization.nil?
71
- vcard_maker.org=(contact.organization)
69
+ def encode_organizations(contact, vcard_maker)
70
+ if !contact.organizations.empty?
71
+ vcard_maker.org = contact.organizations
72
72
  end
73
73
  end
74
74
 
@@ -99,9 +99,11 @@ class Ppl::Adapter::Vcard::Vpim
99
99
  end
100
100
  end
101
101
 
102
- def decode_organization(vcard, contact)
103
- if !vcard.org.nil?
104
- contact.organization = vcard.org.first
102
+ def decode_organizations(vcard, contact)
103
+ if vcard.org.is_a?(Array)
104
+ contact.organizations = vcard.org
105
+ elsif !vcard.org.nil?
106
+ contact.organizations.push(vcard.org)
105
107
  end
106
108
  end
107
109
 
@@ -122,10 +124,8 @@ class Ppl::Adapter::Vcard::Vpim
122
124
  end
123
125
  end
124
126
 
125
- def decode_phone_number(vcard, contact)
126
- if !vcard.telephones.empty?
127
- contact.phone_number = vcard.telephones.first
128
- end
127
+ def decode_phone_numbers(vcard, contact)
128
+ vcard.telephones.each { |number| contact.phone_numbers.push(number) }
129
129
  end
130
130
 
131
131
  def decode_urls(vcard, contact)
@@ -0,0 +1,56 @@
1
+
2
+ class Ppl::Command::Attribute < Ppl::Application::Command
3
+
4
+ attr_writer :attribute
5
+ attr_writer :list_format
6
+ attr_writer :show_format
7
+
8
+ def execute(input, output)
9
+ action = determine_action(input)
10
+ send(action, input, output)
11
+ end
12
+
13
+
14
+ private
15
+
16
+ def determine_action(input)
17
+ if input.arguments[0].nil?
18
+ :list_attribute
19
+ elsif input.arguments[1].nil?
20
+ :show_attribute
21
+ elsif input.options[:delete]
22
+ :remove_attribute
23
+ else
24
+ :add_attribute
25
+ end
26
+ end
27
+
28
+ def list_attribute(input, output)
29
+ address_book = @storage.load_address_book
30
+ output.line(@list_format.process(address_book))
31
+ true
32
+ end
33
+
34
+ def show_attribute(input, output)
35
+ contact = @storage.require_contact(input.arguments[0])
36
+ output.line(@show_format.process(contact))
37
+ true
38
+ end
39
+
40
+ def add_attribute(input, output)
41
+ contact = @storage.require_contact(input.arguments[0])
42
+ values = contact.send(@attribute)
43
+ values.push(input.arguments[1].dup)
44
+ @storage.save_contact(contact)
45
+ true
46
+ end
47
+
48
+ def remove_attribute(input, output)
49
+ contact = @storage.require_contact(input.arguments[0])
50
+ values = contact.send(@attribute)
51
+ values.delete(input.arguments[1])
52
+ @storage.save_contact(contact)
53
+ end
54
+
55
+ end
56
+
@@ -1,83 +1,21 @@
1
1
 
2
- class Ppl::Command::Email < Ppl::Application::Command
2
+ class Ppl::Command::Email < Ppl::Command::Attribute
3
3
 
4
4
  name "email"
5
5
  description "Show or change a contact's email address"
6
6
 
7
- attr_writer :show_format
8
- attr_writer :list_format
9
-
10
7
  def initialize
8
+ @attribute = :email_addresses
11
9
  @show_format = Ppl::Format::Contact::EmailAddresses.new
12
10
  @list_format = Ppl::Format::AddressBook::EmailAddresses.new
13
11
  end
14
12
 
15
13
  def options(parser, options)
16
14
  parser.banner = "usage: ppl email <contact> [<email-address>]"
17
-
18
15
  parser.on("-d", "--delete", "delete email address") do
19
16
  options[:delete] = true
20
17
  end
21
18
  end
22
19
 
23
- def execute(input, output)
24
- action = determine_action(input)
25
- send(action, input, output)
26
- end
27
-
28
-
29
- private
30
-
31
- def determine_action(input)
32
- if input.arguments[0].nil?
33
- :list_email_addresses
34
- elsif input.arguments[1].nil?
35
- :show_email_addresses
36
- elsif input.options[:delete]
37
- :delete_email_address
38
- else
39
- :set_email_address
40
- end
41
- end
42
-
43
- def list_email_addresses(input, output)
44
- address_book = @storage.load_address_book
45
- email_list = @list_format.process(address_book)
46
- output.line(email_list)
47
- end
48
-
49
- def show_email_addresses(input, output)
50
- contact = @storage.require_contact(input.arguments[0])
51
- email_address = @show_format.process(contact)
52
- if email_address != ""
53
- output.line(email_address)
54
- true
55
- else
56
- false
57
- end
58
- end
59
-
60
- def delete_email_address(input, output)
61
- contact = @storage.require_contact(input.arguments[0])
62
- email_address = input.arguments[1].dup
63
- contact.email_addresses.delete(email_address) do
64
- message = sprintf("%s has no such email address %s", contact.id, email_address)
65
- raise Ppl::Error::IncorrectUsage, message
66
- end
67
- @storage.save_contact(contact)
68
- end
69
-
70
- def set_email_address(input, output)
71
- contact = @storage.require_contact(input.arguments[0])
72
- email_address = input.arguments[1].dup
73
- if contact.has_email_address?(email_address)
74
- message = sprintf("%s already has email address %s", contact.id, email_address)
75
- raise Ppl::Error::IncorrectUsage, message
76
- else
77
- contact.email_addresses.push(email_address)
78
- end
79
- @storage.save_contact(contact)
80
- end
81
-
82
20
  end
83
21
 
@@ -1,61 +1,21 @@
1
1
 
2
- class Ppl::Command::Org < Ppl::Application::Command
2
+ class Ppl::Command::Org < Ppl::Command::Attribute
3
3
 
4
4
  name "org"
5
5
  description "List, show or change organizations"
6
6
 
7
- attr_writer :show_format
8
- attr_writer :list_format
9
-
10
7
  def initialize
8
+ @attribute = :organizations
11
9
  @show_format = Ppl::Format::Contact::Organization.new
12
10
  @list_format = Ppl::Format::AddressBook::Organizations.new
13
11
  end
14
12
 
15
13
  def options(parser, options)
16
14
  parser.banner = "usage: ppl org <contact> [<organization>]"
17
- end
18
-
19
- def execute(input, output)
20
- action = determine_action(input)
21
- send(action, input, output)
22
- end
23
-
24
-
25
- private
26
-
27
- def determine_action(input)
28
- if input.arguments[0].nil?
29
- :list_organizations
30
- elsif input.arguments[1].nil?
31
- :show_organization
32
- else
33
- :set_organization
15
+ parser.on("-d", "--delete", "delete organization") do
16
+ options[:delete] = true
34
17
  end
35
18
  end
36
19
 
37
- def list_organizations(input, output)
38
- address_book = @storage.load_address_book
39
- org_list = @list_format.process(address_book)
40
- output.line(org_list)
41
- end
42
-
43
- def show_organization(input, output)
44
- contact = @storage.require_contact(input.arguments[0])
45
- organization = @show_format.process(contact)
46
- if organization != ""
47
- output.line(organization)
48
- true
49
- else
50
- false
51
- end
52
- end
53
-
54
- def set_organization(input, output)
55
- contact = @storage.require_contact(input.arguments[0])
56
- contact.organization = input.arguments[1].dup
57
- @storage.save_contact(contact)
58
- end
59
-
60
20
  end
61
21
 
@@ -1,61 +1,21 @@
1
1
 
2
- class Ppl::Command::Phone < Ppl::Application::Command
2
+ class Ppl::Command::Phone < Ppl::Command::Attribute
3
3
 
4
4
  name "phone"
5
5
  description "List, show or change phone numbers"
6
6
 
7
- attr_writer :show_format
8
- attr_writer :list_format
9
-
10
7
  def initialize
8
+ @attribute = :phone_numbers
11
9
  @show_format = Ppl::Format::Contact::PhoneNumber.new
12
10
  @list_format = Ppl::Format::AddressBook::PhoneNumbers.new
13
11
  end
14
12
 
15
13
  def options(parser, options)
16
14
  parser.banner = "usage: ppl phone <contact> [<number>]"
17
- end
18
-
19
- def execute(input, output)
20
- action = determine_action(input)
21
- send(action, input, output)
22
- end
23
-
24
-
25
- private
26
-
27
- def determine_action(input)
28
- if input.arguments[0].nil?
29
- :list_phone_numbers
30
- elsif input.arguments[1].nil?
31
- :show_phone_number
32
- else
33
- :set_phone_number
15
+ parser.on("-d", "--delete", "delete phone number") do
16
+ options[:delete] = true
34
17
  end
35
18
  end
36
19
 
37
- def list_phone_numbers(input, output)
38
- address_book = @storage.load_address_book
39
- number_list = @list_format.process(address_book)
40
- output.line(number_list)
41
- end
42
-
43
- def show_phone_number(input, output)
44
- contact = @storage.require_contact(input.arguments[0])
45
- number = @show_format.process(contact)
46
- if number != ""
47
- output.line(number)
48
- true
49
- else
50
- false
51
- end
52
- end
53
-
54
- def set_phone_number(input, output)
55
- contact = @storage.require_contact(input.arguments[0])
56
- contact.phone_number = input.arguments[1]
57
- @storage.save_contact(contact)
58
- end
59
-
60
20
  end
61
21
 
@@ -1,13 +1,11 @@
1
1
 
2
- class Ppl::Command::Url < Ppl::Application::Command
2
+ class Ppl::Command::Url < Ppl::Command::Attribute
3
3
 
4
4
  name "url"
5
5
  description "List, show or change URLs"
6
6
 
7
- attr_writer :show_format
8
- attr_writer :list_format
9
-
10
7
  def initialize
8
+ @attribute = :urls
11
9
  @show_format = Ppl::Format::Contact::Urls.new
12
10
  @list_format = Ppl::Format::AddressBook::Urls.new
13
11
  end
@@ -19,64 +17,5 @@ class Ppl::Command::Url < Ppl::Application::Command
19
17
  end
20
18
  end
21
19
 
22
- def execute(input, output)
23
- action = determine_action(input)
24
- send(action, input, output)
25
- end
26
-
27
-
28
- private
29
-
30
- def determine_action(input)
31
- if input.arguments[0].nil?
32
- :list_urls
33
- elsif input.arguments[1].nil?
34
- :show_urls
35
- elsif input.options[:delete]
36
- :delete_url
37
- else
38
- :set_url
39
- end
40
- end
41
-
42
- def list_urls(input, output)
43
- address_book = @storage.load_address_book
44
- url_list = @list_format.process(address_book)
45
- output.line(url_list)
46
- end
47
-
48
- def show_urls(input, output)
49
- contact = @storage.require_contact(input.arguments[0])
50
- urls = @show_format.process(contact)
51
- if urls != ""
52
- output.line(urls)
53
- true
54
- else
55
- false
56
- end
57
- end
58
-
59
- def delete_url(input, output)
60
- contact = @storage.require_contact(input.arguments[0])
61
- old_url = input.arguments[1].dup
62
- contact.urls.delete(old_url) do
63
- message = sprintf("%s has no such url %s", contact.id, old_url)
64
- raise Ppl::Error::IncorrectUsage, message
65
- end
66
- @storage.save_contact(contact)
67
- end
68
-
69
- def set_url(input, output)
70
- contact = @storage.require_contact(input.arguments[0])
71
- new_url = input.arguments[1].dup
72
- if contact.urls.include?(new_url)
73
- message = sprintf("%s already has url %s", contact.id, new_url)
74
- raise Ppl::Error::IncorrectUsage, message
75
- else
76
- contact.urls.push(new_url)
77
- end
78
- @storage.save_contact(contact)
79
- end
80
-
81
20
  end
82
21
 
@@ -5,13 +5,15 @@ class Ppl::Entity::Contact
5
5
  attr_accessor :name
6
6
  attr_accessor :email_addresses
7
7
  attr_accessor :birthday
8
- attr_accessor :phone_number
9
- attr_accessor :organization
8
+ attr_accessor :phone_numbers
9
+ attr_accessor :organizations
10
10
  attr_accessor :postal_address
11
11
  attr_accessor :urls
12
12
 
13
13
  def initialize
14
14
  @email_addresses = []
15
+ @organizations = []
16
+ @phone_numbers = []
15
17
  @urls = []
16
18
  end
17
19
 
@@ -4,7 +4,7 @@ class Ppl::Format::AddressBook::Organizations < Ppl::Format::AddressBook
4
4
  attr_writer :table
5
5
 
6
6
  def initialize
7
- @table = Ppl::Format::Table.new([:id, :organization])
7
+ @table = Ppl::Format::Table.new([:id, :organizations])
8
8
  end
9
9
 
10
10
  def process(address_book)
@@ -16,16 +16,9 @@ class Ppl::Format::AddressBook::Organizations < Ppl::Format::AddressBook
16
16
  private
17
17
 
18
18
  def add_row(contact)
19
- contact_id = sprintf("%s:", contact.id)
20
- organization = nil
21
-
22
- if !contact.organization.nil?
23
- organization = contact.organization
24
- end
25
-
26
19
  @table.add_row({
27
- :id => contact_id,
28
- :organization => organization,
20
+ :id => sprintf("%s:", contact.id),
21
+ :organizations => contact.organizations.join(", "),
29
22
  })
30
23
  end
31
24
 
@@ -4,7 +4,7 @@ class Ppl::Format::AddressBook::PhoneNumbers < Ppl::Format::AddressBook
4
4
  attr_writer :table
5
5
 
6
6
  def initialize
7
- @table = Ppl::Format::Table.new([:id, :phone_number])
7
+ @table = Ppl::Format::Table.new([:id, :phone_numbers])
8
8
  end
9
9
 
10
10
  def process(address_book)
@@ -16,19 +16,11 @@ class Ppl::Format::AddressBook::PhoneNumbers < Ppl::Format::AddressBook
16
16
  private
17
17
 
18
18
  def add_row(contact)
19
- contact_id = sprintf("%s:", contact.id)
20
- phone_number = nil
21
-
22
- if !contact.phone_number.nil?
23
- phone_number = contact.phone_number
24
- end
25
-
26
19
  @table.add_row({
27
- :id => contact_id,
28
- :phone_number => phone_number,
20
+ :id => sprintf("%s:", contact.id),
21
+ :phone_numbers => contact.phone_numbers.join(", "),
29
22
  })
30
23
  end
31
24
 
32
-
33
25
  end
34
26
 
@@ -21,6 +21,7 @@ class Ppl::Format::Contact::Full < Ppl::Format::Contact
21
21
  @lines.push(vitals)
22
22
  end
23
23
 
24
+ format_organizations(contact)
24
25
  format_email_addresses(contact)
25
26
  format_phone_numbers(contact)
26
27
  format_postal_addresses(contact)
@@ -47,9 +48,6 @@ class Ppl::Format::Contact::Full < Ppl::Format::Contact
47
48
  if !contact.birthday.nil?
48
49
  vitals.push(format_vital("Birthday", contact.birthday.strftime("%Y-%m-%d")))
49
50
  end
50
- if !contact.organization.nil?
51
- vitals.push(format_vital("Organization", contact.organization))
52
- end
53
51
  return vitals.join("\n")
54
52
  end
55
53
 
@@ -57,14 +55,16 @@ class Ppl::Format::Contact::Full < Ppl::Format::Contact
57
55
  return sprintf(" %-12s %s", name, value)
58
56
  end
59
57
 
58
+ def format_organizations(contact)
59
+ push_list("Organizations", contact.organizations)
60
+ end
61
+
60
62
  def format_email_addresses(contact)
61
63
  push_list("Email Addresses", contact.email_addresses)
62
64
  end
63
65
 
64
66
  def format_phone_numbers(contact)
65
- if !contact.phone_number.nil?
66
- push_list("Phone Numbers", contact.phone_number)
67
- end
67
+ push_list("Phone Numbers", contact.phone_numbers)
68
68
  end
69
69
 
70
70
  def format_postal_addresses(contact)
@@ -2,11 +2,7 @@
2
2
  class Ppl::Format::Contact::Organization < Ppl::Format::Contact
3
3
 
4
4
  def process(contact)
5
- output = ""
6
- if !contact.organization.nil?
7
- output += contact.organization
8
- end
9
- return output
5
+ contact.organizations.join("\n")
10
6
  end
11
7
 
12
8
  end
@@ -2,11 +2,7 @@
2
2
  class Ppl::Format::Contact::PhoneNumber < Ppl::Format::Contact
3
3
 
4
4
  def process(contact)
5
- output = ""
6
- if !contact.phone_number.nil?
7
- output += contact.phone_number
8
- end
9
- return output
5
+ contact.phone_numbers.join("\n")
10
6
  end
11
7
 
12
8
  end
data/lib/ppl.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Ppl
3
3
 
4
- Version = "1.9.0"
4
+ Version = "1.10.0"
5
5
 
6
6
  module Adapter
7
7
  end
@@ -40,6 +40,7 @@ require "ppl/application/output"
40
40
  require "ppl/application/router"
41
41
  require "ppl/application/shell"
42
42
 
43
+ require "ppl/command/attribute"
43
44
  require "ppl/command/init"
44
45
  require "ppl/command/bday"
45
46
  require "ppl/command/ls"
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 = "1.9.0"
6
- spec.date = "2013-01-06"
5
+ spec.version = "1.10.0"
6
+ spec.date = "2013-01-10"
7
7
 
8
8
  spec.required_ruby_version = ">= 1.9.3"
9
9
 
@@ -23,12 +23,12 @@ describe Ppl::Adapter::Vcard::Vpim, "#encode" do
23
23
  end
24
24
 
25
25
  it "should encode the contact's phone number" do
26
- @contact.phone_number = "01234567890"
26
+ @contact.phone_numbers.push("01234567890")
27
27
  @adapter.encode(@contact).should include("TEL:01234567890")
28
28
  end
29
29
 
30
30
  it "should encode the contact's organization" do
31
- @contact.organization = "Example Ltd"
31
+ @contact.organizations.push("Example Ltd")
32
32
  @adapter.encode(@contact).should include("ORG:Example Ltd")
33
33
  end
34
34
 
@@ -138,7 +138,7 @@ describe Ppl::Adapter::Vcard::Vpim, "#decode" do
138
138
  "END:VCARD",
139
139
  ].join("\n")
140
140
  contact = @adapter.decode(vcard)
141
- contact.phone_number.should eq "01234567890"
141
+ contact.phone_numbers.first.should eq "01234567890"
142
142
  end
143
143
 
144
144
  it "should decode the contact's organization" do
@@ -150,7 +150,7 @@ describe Ppl::Adapter::Vcard::Vpim, "#decode" do
150
150
  "END:VCARD",
151
151
  ].join("\n")
152
152
  contact = @adapter.decode(vcard)
153
- contact.organization.should eq "Example Ltd"
153
+ contact.organizations.first.should eq "Example Ltd"
154
154
  end
155
155
 
156
156
  it "should decode the contact's street address" do
@@ -0,0 +1,62 @@
1
+
2
+ describe Ppl::Command::Attribute do
3
+
4
+ before(:each) do
5
+ @attribute = :phone_numbers
6
+ @command = Ppl::Command::Attribute.new
7
+ @input = Ppl::Application::Input.new
8
+ @output = double(Ppl::Application::Output)
9
+ @storage = double(Ppl::Adapter::Storage)
10
+ @list_format = double(Ppl::Format::AddressBook)
11
+ @show_format = double(Ppl::Format::Contact)
12
+ @address_book = double(Ppl::Entity::AddressBook)
13
+ @contact = double(Ppl::Entity::Contact)
14
+
15
+ @command.attribute = @attribute
16
+ @command.list_format = @list_format
17
+ @command.show_format = @show_format
18
+ @command.storage = @storage
19
+ end
20
+
21
+
22
+ describe "#execute" do
23
+
24
+ it "should list all the contacts and the value of the attribute for each" do
25
+ @storage.should_receive(:load_address_book).and_return(@address_book)
26
+ @list_format.should_receive(:process).and_return("imagine this is a list")
27
+ @output.should_receive(:line).with("imagine this is a list")
28
+ @command.execute(@input, @output).should eq true
29
+ end
30
+
31
+ it "should show the full list of attributes for the given contact" do
32
+ @input.arguments.push("jdoe")
33
+ @storage.should_receive(:require_contact).and_return(@contact)
34
+ @show_format.should_receive(:process).and_return("all the info")
35
+ @output.should_receive(:line).with("all the info")
36
+ @command.execute(@input, @output).should eq true
37
+ end
38
+
39
+ it "should add the given value to the contact's attributes" do
40
+ @input.arguments.push("jdoe", "anyvalue")
41
+ @storage.should_receive(:require_contact).and_return(@contact)
42
+ @contact.should_receive(:phone_numbers).and_return([])
43
+ @storage.should_receive(:save_contact)
44
+ @command.execute(@input, @output).should eq true
45
+ end
46
+
47
+ it "should delete the given value from the contact's attributes" do
48
+ phone_numbers = double(Array)
49
+ phone_numbers.should_receive(:delete)
50
+
51
+ @storage.should_receive(:require_contact).and_return(@contact)
52
+ @contact.should_receive(:phone_numbers).and_return(phone_numbers)
53
+ @storage.should_receive(:save_contact).and_return(true)
54
+ @input.arguments = ["jdoe", "somevalue"]
55
+ @input.options = { :delete => true }
56
+ @command.execute(@input, @output).should eq true
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+
@@ -2,19 +2,7 @@
2
2
  describe Ppl::Command::Email do
3
3
 
4
4
  before(:each) do
5
- @input = Ppl::Application::Input.new
6
- @output = Ppl::Application::Output.new(nil, nil)
7
- @contact = Ppl::Entity::Contact.new
8
5
  @command = Ppl::Command::Email.new
9
- @storage = double(Ppl::Adapter::Storage)
10
-
11
- @list_format = double(Ppl::Format::Contact)
12
- @show_format = double(Ppl::Format::Contact)
13
-
14
- @command.storage = @storage
15
- @command.show_format = @show_format
16
- @command.list_format = @list_format
17
- @contact.id = "jim"
18
6
  end
19
7
 
20
8
  describe "#name" do
@@ -23,69 +11,5 @@ describe Ppl::Command::Email do
23
11
  end
24
12
  end
25
13
 
26
- describe "#execute" do
27
-
28
- it "should list all email addresses if no contact ID is given" do
29
- @storage.should_receive(:load_address_book).and_return(@address_book)
30
- @list_format.should_receive(:process).and_return("all the email addresses")
31
- @output.should_receive(:line).with("all the email addresses")
32
- @input.arguments = []
33
- @command.execute(@input, @output)
34
- end
35
-
36
- it "should show the current address if no new address is given" do
37
- @storage.should_receive(:require_contact).and_return(@contact)
38
- @show_format.should_receive(:process).and_return("jdoe@example.org")
39
- @output.should_receive(:line).with("jdoe@example.org")
40
- @input.arguments = ["jim"]
41
- @command.execute(@input, @output).should eq true
42
- end
43
-
44
- it "should not output anything if there's nothing to show" do
45
- @storage.should_receive(:require_contact).and_return(@contact)
46
- @show_format.should_receive(:process).and_return("")
47
- @input.arguments = ["jim"]
48
- @command.execute(@input, @output).should eq false
49
- end
50
-
51
- it "should delete the given address to the contact if requested" do
52
- @contact.email_addresses.push("jim@example.org")
53
- @contact.email_addresses.push("jim@example.com")
54
- @storage.should_receive(:require_contact).and_return(@contact)
55
- @storage.should_receive(:save_contact) do |contact|
56
- contact.email_addresses.should eq ["jim@example.com"]
57
- end
58
- @input.arguments = ["jim", "jim@example.org"]
59
- @input.options = { :delete => true }
60
- @command.execute(@input, @output)
61
- end
62
-
63
- it "should raise an error when deleting a non-existent email address" do
64
- @contact.email_addresses.push("jim@example.org")
65
- @contact.email_addresses.push("jim@example.com")
66
- @storage.should_receive(:require_contact).and_return(@contact)
67
- @input.arguments = ["jim", "jim@example.net"]
68
- @input.options = { :delete => true }
69
- expect{@command.execute(@input, nil)}.to raise_error(Ppl::Error::IncorrectUsage)
70
- end
71
-
72
- it "should add the given address to the contact if it's new" do
73
- @storage.should_receive(:require_contact).and_return(@contact)
74
- @storage.should_receive(:save_contact) do |contact|
75
- contact.email_addresses.first.should eq "jim@example.org"
76
- end
77
- @input.arguments = ["jim", "jim@example.org"]
78
- @command.execute(@input, @output)
79
- end
80
-
81
- it "should raise an error if the user is adding a duplicate address" do
82
- @contact.email_addresses.push "jim@example.org"
83
- @storage.should_receive(:require_contact).and_return(@contact)
84
- @input.arguments = ["jim", "jim@example.org"]
85
- expect{@command.execute(@input, nil)}.to raise_error(Ppl::Error::IncorrectUsage)
86
- end
87
-
88
- end
89
-
90
14
  end
91
15
 
@@ -3,19 +3,6 @@ describe Ppl::Command::Org do
3
3
 
4
4
  before(:each) do
5
5
  @command = Ppl::Command::Org.new
6
- @input = Ppl::Application::Input.new
7
- @output = Ppl::Application::Output.new(nil, nil)
8
- @contact = Ppl::Entity::Contact.new
9
- @storage = double(Ppl::Adapter::Storage)
10
-
11
- @show_format = double(Ppl::Format::Contact)
12
- @list_format = double(Ppl::Format::Contact)
13
-
14
- @command.storage = @storage
15
- @command.show_format = @show_format
16
- @command.list_format = @list_format
17
-
18
- @contact.id = "tim"
19
6
  end
20
7
 
21
8
  describe "#name" do
@@ -24,41 +11,5 @@ describe Ppl::Command::Org do
24
11
  end
25
12
  end
26
13
 
27
- describe "#execute" do
28
-
29
- it "should list all organizations if no contact ID is given" do
30
- @storage.should_receive(:load_address_book).and_return(@address_book)
31
- @list_format.should_receive(:process).and_return("all the organizations")
32
- @output.should_receive(:line).with("all the organizations")
33
- @input.arguments = []
34
- @command.execute(@input, @output)
35
- end
36
-
37
- it "should show the contact's organization if no new organization is given" do
38
- @storage.should_receive(:require_contact).and_return(@contact)
39
- @show_format.should_receive(:process).and_return("Example Ltd")
40
- @output.should_receive(:line).with("Example Ltd")
41
- @input.arguments = ["jim"]
42
- @command.execute(@input, @output).should eq true
43
- end
44
-
45
- it "should not output anything if there's nothing to show" do
46
- @storage.should_receive(:require_contact).and_return(@contact)
47
- @show_format.should_receive(:process).and_return("")
48
- @input.arguments = ["jim"]
49
- @command.execute(@input, @output).should eq false
50
- end
51
-
52
- it "should change the contact's organization if one is given" do
53
- @storage.should_receive(:require_contact).and_return(@contact)
54
- @storage.should_receive(:save_contact) do |contact|
55
- contact.organization.should eq "Example Ltd"
56
- end
57
- @input.arguments = ["jim", "Example Ltd"]
58
- @command.execute(@input, @output)
59
- end
60
-
61
- end
62
-
63
14
  end
64
15
 
@@ -3,17 +3,6 @@ describe Ppl::Command::Phone do
3
3
 
4
4
  before(:each) do
5
5
  @command = Ppl::Command::Phone.new
6
- @input = Ppl::Application::Input.new
7
- @output = Ppl::Application::Output.new(nil, nil)
8
- @contact = Ppl::Entity::Contact.new
9
- @storage = double(Ppl::Adapter::Storage)
10
-
11
- @show_format = double(Ppl::Format::Contact)
12
- @list_format = double(Ppl::Format::Contact)
13
-
14
- @command.storage = @storage
15
- @command.show_format = @show_format
16
- @command.list_format = @list_format
17
6
  end
18
7
 
19
8
  describe "#name" do
@@ -22,41 +11,5 @@ describe Ppl::Command::Phone do
22
11
  end
23
12
  end
24
13
 
25
- describe "#execute" do
26
-
27
- it "should list all phone numbers if no contact ID is given" do
28
- @storage.should_receive(:load_address_book).and_return(@address_book)
29
- @list_format.should_receive(:process).and_return("all the numbers")
30
- @output.should_receive(:line).with("all the numbers")
31
- @input.arguments = []
32
- @command.execute(@input, @output)
33
- end
34
-
35
- it "should show the contact's phone number if no new number is given" do
36
- @storage.should_receive(:require_contact).and_return(@contact)
37
- @show_format.should_receive(:process).and_return("0123456789")
38
- @output.should_receive(:line).with("0123456789")
39
- @input.arguments = ["jim"]
40
- @command.execute(@input, @output).should eq true
41
- end
42
-
43
- it "should not output anything if there's nothing to show" do
44
- @storage.should_receive(:require_contact).and_return(@contact)
45
- @show_format.should_receive(:process).and_return("")
46
- @input.arguments = ["jim"]
47
- @command.execute(@input, @output).should eq false
48
- end
49
-
50
- it "should change the contact's phone number if a number is given" do
51
- @storage.should_receive(:require_contact).and_return(@contact)
52
- @storage.should_receive(:save_contact) do |contact|
53
- contact.phone_number.should eq "01234567890"
54
- end
55
- @input.arguments = ["jim", "01234567890"]
56
- @command.execute(@input, @output)
57
- end
58
-
59
- end
60
-
61
14
  end
62
15
 
@@ -3,18 +3,6 @@ describe Ppl::Command::Url do
3
3
 
4
4
  before(:each) do
5
5
  @command = Ppl::Command::Url.new
6
- @input = Ppl::Application::Input.new
7
- @output = Ppl::Application::Output.new(nil, nil)
8
- @contact = Ppl::Entity::Contact.new
9
- @storage = double(Ppl::Adapter::Storage)
10
-
11
- @list_format = double(Ppl::Format::Contact)
12
- @show_format = double(Ppl::Format::Contact)
13
-
14
- @command.storage = @storage
15
- @command.show_format = @show_format
16
- @command.list_format = @list_format
17
- @contact.id = "jim"
18
6
  end
19
7
 
20
8
  describe "#name" do
@@ -23,69 +11,5 @@ describe Ppl::Command::Url do
23
11
  end
24
12
  end
25
13
 
26
- describe "#execute" do
27
-
28
- it "should list all URLs if no contact ID is given" do
29
- @storage.should_receive(:load_address_book).and_return(@address_book)
30
- @list_format.should_receive(:process).and_return("all the URLs")
31
- @output.should_receive(:line).with("all the URLs")
32
- @input.arguments = []
33
- @command.execute(@input, @output)
34
- end
35
-
36
- it "should show the current URLs if no new URL is given" do
37
- @storage.should_receive(:require_contact).and_return(@contact)
38
- @show_format.should_receive(:process).and_return("http://example.org/~jdoe")
39
- @output.should_receive(:line).with("http://example.org/~jdoe")
40
- @input.arguments = ["jim"]
41
- @command.execute(@input, @output).should eq true
42
- end
43
-
44
- it "should not output anything if there's nothing to show" do
45
- @storage.should_receive(:require_contact).and_return(@contact)
46
- @show_format.should_receive(:process).and_return("")
47
- @input.arguments = ["jim"]
48
- @command.execute(@input, @output).should eq false
49
- end
50
-
51
- it "should delete the given URL from the contact if requested" do
52
- @contact.urls.push("http://example.org/~jdoe")
53
- @contact.urls.push("http://example.com/~jdoe")
54
- @storage.should_receive(:require_contact).and_return(@contact)
55
- @storage.should_receive(:save_contact) do |contact|
56
- contact.urls.should eq ["http://example.com/~jdoe"]
57
- end
58
- @input.arguments = ["jim", "http://example.org/~jdoe"]
59
- @input.options = { :delete => true }
60
- @command.execute(@input, @output)
61
- end
62
-
63
- it "should raise an error when deleting a non-existent URL" do
64
- @contact.urls.push("http://example.org/~jdoe")
65
- @contact.urls.push("http://example.com/~jdoe")
66
- @storage.should_receive(:require_contact).and_return(@contact)
67
- @input.arguments = ["jim", "http://example.net/~jdoe"]
68
- @input.options = { :delete => true }
69
- expect{@command.execute(@input, nil)}.to raise_error(Ppl::Error::IncorrectUsage)
70
- end
71
-
72
- it "should add the given URL to the contact if it's new" do
73
- @storage.should_receive(:require_contact).and_return(@contact)
74
- @storage.should_receive(:save_contact) do |contact|
75
- contact.urls.first.should eq "http://example.org/~jdoe"
76
- end
77
- @input.arguments = ["jim", "http://example.org/~jdoe"]
78
- @command.execute(@input, @output)
79
- end
80
-
81
- it "should raise an error if the user is adding a duplicate address" do
82
- @contact.urls.push "http://example.org/~jdoe"
83
- @storage.should_receive(:require_contact).and_return(@contact)
84
- @input.arguments = ["jim", "http://example.org/~jdoe"]
85
- expect{@command.execute(@input, nil)}.to raise_error(Ppl::Error::IncorrectUsage)
86
- end
87
-
88
- end
89
-
90
14
  end
91
15
 
@@ -52,5 +52,17 @@ describe Ppl::Entity::Contact do
52
52
  end
53
53
  end
54
54
 
55
+ describe "#organizations" do
56
+ it "should return an array" do
57
+ @contact.organizations.should be_a(Array)
58
+ end
59
+ end
60
+
61
+ describe "#phone_numbers" do
62
+ it "should return an array" do
63
+ @contact.phone_numbers.should be_a(Array)
64
+ end
65
+ end
66
+
55
67
  end
56
68
 
@@ -17,17 +17,17 @@ describe Ppl::Format::AddressBook::Organizations 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
- :organization => nil,
20
+ :id => "test:",
21
+ :organizations => "",
22
22
  })
23
23
  @format.process(@address_book)
24
24
  end
25
25
 
26
26
  it "should show the organization if it's available" do
27
- @contact.organization = "Example Ltd"
27
+ @contact.organizations.push("Example Ltd")
28
28
  @table.should_receive(:add_row).with({
29
- :id => "test:",
30
- :organization => "Example Ltd",
29
+ :id => "test:",
30
+ :organizations => "Example Ltd",
31
31
  })
32
32
  @format.process(@address_book)
33
33
  end
@@ -17,17 +17,17 @@ describe Ppl::Format::AddressBook::PhoneNumbers 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
- :phone_number => nil,
20
+ :id => "test:",
21
+ :phone_numbers => "",
22
22
  })
23
23
  @format.process(@address_book)
24
24
  end
25
25
 
26
26
  it "should show the phone number if it's available" do
27
- @contact.phone_number = "01234567890"
27
+ @contact.phone_numbers.push("01234567890")
28
28
  @table.should_receive(:add_row).with({
29
- :id => "test:",
30
- :phone_number => "01234567890",
29
+ :id => "test:",
30
+ :phone_numbers => "01234567890",
31
31
  })
32
32
  @format.process(@address_book)
33
33
  end
@@ -42,12 +42,12 @@ describe Ppl::Format::Contact::Full do
42
42
  end
43
43
 
44
44
  it "should show their phone number if available" do
45
- @contact.phone_number = "01234567890"
45
+ @contact.phone_numbers.push("01234567890")
46
46
  @format.process(@contact).should include "01234567890"
47
47
  end
48
48
 
49
- it "should show their organization if available" do
50
- @contact.organization = "Example Ltd"
49
+ it "should show all their organizations" do
50
+ @contact.organizations.push("Example Ltd")
51
51
  @format.process(@contact).should include "Example Ltd"
52
52
  end
53
53
 
@@ -13,7 +13,7 @@ describe Ppl::Format::Contact::Organization do
13
13
  end
14
14
 
15
15
  it "should return the contact's organization if it is set" do
16
- @contact.organization = "Example Ltd"
16
+ @contact.organizations.push("Example Ltd")
17
17
  @format.process(@contact).should eq "Example Ltd"
18
18
  end
19
19
 
@@ -13,7 +13,7 @@ describe Ppl::Format::Contact::PhoneNumber do
13
13
  end
14
14
 
15
15
  it "should return the contact's phone number if it is set" do
16
- @contact.phone_number = "0123456789"
16
+ @contact.phone_numbers.push("0123456789")
17
17
  @format.process(@contact).should eq "0123456789"
18
18
  end
19
19
 
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.9.0
4
+ version: 1.10.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: 2013-01-06 00:00:00.000000000 Z
12
+ date: 2013-01-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: inifile
16
- requirement: &18641320 !ruby/object:Gem::Requirement
16
+ requirement: &3232880 !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: *18641320
24
+ version_requirements: *3232880
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rugged
27
- requirement: &18640600 !ruby/object:Gem::Requirement
27
+ requirement: &3230760 !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: *18640600
35
+ version_requirements: *3230760
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: vpim
38
- requirement: &18640020 !ruby/object:Gem::Requirement
38
+ requirement: &3228280 !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: *18640020
46
+ version_requirements: *3228280
47
47
  description: CLI Address Book
48
48
  email: henry@henrysmith.org
49
49
  executables:
@@ -75,6 +75,7 @@ files:
75
75
  - lib/ppl/application/router.rb
76
76
  - lib/ppl/application/shell.rb
77
77
  - lib/ppl/command/add.rb
78
+ - lib/ppl/command/attribute.rb
78
79
  - lib/ppl/command/bday.rb
79
80
  - lib/ppl/command/email.rb
80
81
  - lib/ppl/command/help.rb
@@ -134,6 +135,7 @@ files:
134
135
  - spec/ppl/application/router_spec.rb
135
136
  - spec/ppl/application/shell_spec.rb
136
137
  - spec/ppl/command/add_spec.rb
138
+ - spec/ppl/command/attribute_spec.rb
137
139
  - spec/ppl/command/bday_spec.rb
138
140
  - spec/ppl/command/email_spec.rb
139
141
  - spec/ppl/command/help_spec.rb