ppl 1.20.0 → 1.21.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2c1a083b23b90a24e6f81e381593c1ed37150e1
4
- data.tar.gz: e8477cde9b1eec569179e8695c65da79878f5925
3
+ metadata.gz: 23ea84dcda4441890c0bb20f27fa04e5c6235706
4
+ data.tar.gz: 609844a6af38ff976f7e4a1167b5ef581d755587
5
5
  SHA512:
6
- metadata.gz: 6526a4a9e7a9aebfb8172736570852731ec890e15c5d74be9851a89c9a4f34c3599d0c10368252a038aafa6a7e4a8b6ca127821dd3e035b16af2cbc4d12969a0
7
- data.tar.gz: a8abdf21b1ef7faea30160279c1fcf0e7ebf1e71138e1c8232ffdd2ea9b893a1b1773655e773cf7b77009cd653357a28e85cbe6dbf49ff5da4f839cb84600a47
6
+ metadata.gz: 3df8d5dc16d1ba121e314fb70d80448f1394c6e4779a63f5b6f9f29450ed3a8d3115ce5854f752c7386d4614c88adc5f8c42da850be996c525db5d7bdd599482
7
+ data.tar.gz: faf4b9f89b5892f3352a33a4818bb91b754ea526345b078df272658147fa549122ebe6175e5c8be295d03e0446a044de00571bf9cf73ea9e23baf94eb5f81cd9
data/lib/ppl.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Ppl
3
3
 
4
- Version = "1.20.0"
4
+ Version = "1.21.0"
5
5
 
6
6
  module Adapter
7
7
  end
@@ -70,6 +70,7 @@ require "ppl/command/scrape"
70
70
 
71
71
  require "ppl/entity/address_book"
72
72
  require "ppl/entity/contact"
73
+ require "ppl/entity/phone_number"
73
74
  require "ppl/entity/postal_address"
74
75
 
75
76
  require "ppl/error/completion_not_found"
@@ -64,7 +64,9 @@ class Ppl::Adapter::Vcard::GreenCard
64
64
 
65
65
  def encode_phone_numbers(contact, vcard_maker)
66
66
  contact.phone_numbers.each do |phone_number|
67
- vcard_maker.add_tel(phone_number)
67
+ vcard_maker.add_tel(phone_number.number) do |tel|
68
+ tel.location = phone_number.type
69
+ end
68
70
  end
69
71
  end
70
72
 
@@ -131,7 +133,12 @@ class Ppl::Adapter::Vcard::GreenCard
131
133
  end
132
134
 
133
135
  def decode_phone_numbers(vcard, contact)
134
- vcard.telephones.each { |number| contact.phone_numbers.push(number) }
136
+ vcard.telephones.each do |tel|
137
+ phone_number = Ppl::Entity::PhoneNumber.new
138
+ phone_number.number = tel.to_s
139
+ phone_number.type = (tel.location | tel.nonstandard).join
140
+ contact.phone_numbers << phone_number
141
+ end
135
142
  end
136
143
 
137
144
  def decode_urls(vcard, contact)
@@ -13,6 +13,42 @@ class Ppl::Command::Phone < Ppl::Command::Attribute
13
13
  parser.on("-d", "--delete", "delete phone number") do
14
14
  options[:delete] = true
15
15
  end
16
+ parser.on("-t", "--type <type>") do |type|
17
+ options[:type] = type
18
+ end
19
+ end
20
+
21
+ def add_attribute(input, output)
22
+ contact = @storage.require_contact(input.arguments.shift)
23
+ if new_number?(contact, input.arguments[0])
24
+ add_new_number(contact, input)
25
+ else
26
+ update_existing_number(contact, input)
27
+ end
28
+ @storage.save_contact(contact)
29
+ true
30
+ end
31
+
32
+ def new_number?(contact, input_number)
33
+ matching_numbers = contact.phone_numbers.select do |pn|
34
+ pn.number == input_number
35
+ end
36
+ matching_numbers.length < 1
37
+ end
38
+
39
+ def add_new_number(contact, input)
40
+ phone_number = Ppl::Entity::PhoneNumber.new
41
+ phone_number.number = input.arguments[0]
42
+ phone_number.type = input.options[:type]
43
+ contact.phone_numbers << phone_number
44
+ end
45
+
46
+ def update_existing_number(contact, input)
47
+ contact.phone_numbers.each do |pn|
48
+ if pn.number == input.arguments[0]
49
+ pn.type = input.options[:type]
50
+ end
51
+ end
16
52
  end
17
53
 
18
54
  end
@@ -0,0 +1,13 @@
1
+
2
+ class Ppl::Entity::PhoneNumber
3
+
4
+ attr_accessor :number
5
+ attr_accessor :type
6
+
7
+ def initialize(number = nil, type = nil)
8
+ @number = number
9
+ @type = type
10
+ end
11
+
12
+ end
13
+
@@ -18,9 +18,13 @@ class Ppl::Format::AddressBook::PhoneNumbers < Ppl::Format::AddressBook
18
18
  def add_row(contact)
19
19
  @table.add_row({
20
20
  :id => sprintf("%s:", contact.id),
21
- :phone_numbers => contact.phone_numbers.join(", "),
21
+ :phone_numbers => stringify_phone_numbers(contact.phone_numbers)
22
22
  })
23
23
  end
24
24
 
25
+ def stringify_phone_numbers(phone_numbers)
26
+ phone_numbers.map { |pn| pn.number }.join(", ")
27
+ end
28
+
25
29
  end
26
30
 
@@ -1,25 +1,29 @@
1
1
 
2
2
  class Ppl::Format::Contact::PhoneNumber < Ppl::Format::Contact
3
3
 
4
- attr_writer :color_adapter
5
- attr_writer :colors
4
+ attr_writer :table
6
5
 
7
6
  def initialize(colors={})
8
- @colors = colors
9
- @color_adapter = Ppl::Adapter::Color::Colored.new
7
+ @table = Ppl::Format::Table.new([:phone_numbers, :type], colors)
10
8
  end
11
9
 
12
10
  def process(contact)
13
- colorize_output(contact.phone_numbers.join("\n"))
11
+ contact.phone_numbers.each { |pn| add_row(pn) }
12
+ @table.to_s
14
13
  end
15
14
 
16
15
  private
17
16
 
18
- def colorize_output(string)
19
- if @colors["phone_numbers"]
20
- @color_adapter.colorize(string, @colors["phone_numbers"])
21
- else
22
- string
17
+ def add_row(phone_number)
18
+ @table.add_row({
19
+ :phone_numbers => phone_number.number,
20
+ :type => format_type(phone_number.type),
21
+ })
22
+ end
23
+
24
+ def format_type(type)
25
+ unless type.nil? || type == ""
26
+ "(#{type})"
23
27
  end
24
28
  end
25
29
 
@@ -2,8 +2,8 @@
2
2
  Gem::Specification.new do |spec|
3
3
 
4
4
  spec.name = "ppl"
5
- spec.version = "1.20.0"
6
- spec.date = "2013-04-19"
5
+ spec.version = "1.21.0"
6
+ spec.date = "2013-04-20"
7
7
 
8
8
  spec.required_ruby_version = ">= 1.9.3"
9
9
 
@@ -24,10 +24,15 @@ describe Ppl::Adapter::Vcard::GreenCard, "#encode" do
24
24
  end
25
25
 
26
26
  it "should encode the contact's phone number" do
27
- @contact.phone_numbers.push("01234567890")
27
+ @contact.phone_numbers << Ppl::Entity::PhoneNumber.new("01234567890")
28
28
  @adapter.encode(@contact).should include("TEL:01234567890")
29
29
  end
30
30
 
31
+ it "should encode the contact's phone number's type" do
32
+ @contact.phone_numbers << Ppl::Entity::PhoneNumber.new("01234567890", "cell")
33
+ @adapter.encode(@contact).should include("TEL;TYPE=cell:01234567890")
34
+ end
35
+
31
36
  it "should encode the contact's organization" do
32
37
  @contact.organizations.push("Example Ltd")
33
38
  @adapter.encode(@contact).should include("ORG:Example Ltd")
@@ -144,7 +149,34 @@ describe Ppl::Adapter::Vcard::GreenCard, "#decode" do
144
149
  "END:VCARD",
145
150
  ].join("\n")
146
151
  contact = @adapter.decode(vcard)
147
- contact.phone_numbers.first.should eq "01234567890"
152
+ phone_number = contact.phone_numbers.first
153
+ phone_number.number.should eq "01234567890"
154
+ end
155
+
156
+ it "should decode the contact's phone number's type" do
157
+ vcard = [
158
+ "BEGIN:VCARD",
159
+ "N:,test",
160
+ "VERSION:3.0",
161
+ "TEL;TYPE=cell:01234567890",
162
+ "END:VCARD",
163
+ ].join("\n")
164
+ contact = @adapter.decode(vcard)
165
+ phone_number = contact.phone_numbers.first
166
+ phone_number.type.should eq "cell"
167
+ end
168
+
169
+ it "should decode the contact's phone number's nonstandard type" do
170
+ vcard = [
171
+ "BEGIN:VCARD",
172
+ "N:,test",
173
+ "VERSION:3.0",
174
+ "TEL;TYPE=testing:01234567890",
175
+ "END:VCARD",
176
+ ].join("\n")
177
+ contact = @adapter.decode(vcard)
178
+ phone_number = contact.phone_numbers.first
179
+ phone_number.type.should eq "testing"
148
180
  end
149
181
 
150
182
  it "should decode the contact's organization" do
@@ -11,5 +11,49 @@ describe Ppl::Command::Phone do
11
11
  end
12
12
  end
13
13
 
14
+ describe "#execute" do
15
+
16
+ before(:each) do
17
+ @contact = Ppl::Entity::Contact.new
18
+ @storage = double(Ppl::Adapter::Storage)
19
+ @input = Ppl::Application::Input.new
20
+ @input.arguments = ["jdoe", "01234567"]
21
+ @storage.stub(:require_contact).and_return(@contact)
22
+ @storage.stub(:save_contact)
23
+ @command.storage = @storage
24
+ end
25
+
26
+ it "should save phone numbers as instances of Ppl::Entity::PhoneNumber" do
27
+ @storage.should_receive(:save_contact) do |c|
28
+ c.phone_numbers.first.should be_a(Ppl::Entity::PhoneNumber)
29
+ end
30
+ @command.execute(@input, @output)
31
+ end
32
+
33
+ it "should save the given number as an attribute of the PhoneNumber" do
34
+ @storage.should_receive(:save_contact) do |c|
35
+ c.phone_numbers.first.number.should eq "01234567"
36
+ end
37
+ @command.execute(@input, @output)
38
+ end
39
+
40
+ it "should save the given type alongside the number" do
41
+ @input.options[:type] = "cell"
42
+ @storage.should_receive(:save_contact) do |c|
43
+ c.phone_numbers.first.type.should eq "cell"
44
+ end
45
+ @command.execute(@input, @output)
46
+ end
47
+
48
+ it "shouldn't duplicate the number if the contact already has it" do
49
+ @contact.phone_numbers << Ppl::Entity::PhoneNumber.new("01234567")
50
+ @storage.should_receive(:save_contact) do |c|
51
+ c.phone_numbers.length.should eq 1
52
+ end
53
+ @command.execute(@input, @output)
54
+ end
55
+
56
+ end
57
+
14
58
  end
15
59
 
@@ -0,0 +1,32 @@
1
+
2
+ describe Ppl::Entity::PhoneNumber do
3
+
4
+ before(:each) do
5
+ @phone_number = Ppl::Entity::PhoneNumber.new
6
+ end
7
+
8
+ describe "#number" do
9
+ it "should return a value" do
10
+ @phone_number.number.should eq nil
11
+ end
12
+ end
13
+
14
+ describe "#type" do
15
+ it "should return a value" do
16
+ @phone_number.type.should eq nil
17
+ end
18
+ end
19
+
20
+ describe "#initialize" do
21
+ it "should accept a number" do
22
+ phone = Ppl::Entity::PhoneNumber.new(12345)
23
+ phone.number.should eq 12345
24
+ end
25
+ it "should accept a type" do
26
+ phone = Ppl::Entity::PhoneNumber.new(nil, "cell")
27
+ phone.type.should eq "cell"
28
+ end
29
+ end
30
+
31
+ end
32
+
@@ -34,7 +34,7 @@ describe Ppl::Format::AddressBook::PhoneNumbers do
34
34
  end
35
35
 
36
36
  it "should show the phone number if it's available" do
37
- @contact.phone_numbers.push("01234567890")
37
+ @contact.phone_numbers << Ppl::Entity::PhoneNumber.new("01234567890")
38
38
  @table.should_receive(:add_row).with({
39
39
  :id => "test:",
40
40
  :phone_numbers => "01234567890",
@@ -1,31 +1,44 @@
1
1
 
2
2
  describe Ppl::Format::Contact::PhoneNumber do
3
3
 
4
- before(:each) do
5
- @format = Ppl::Format::Contact::PhoneNumber.new
6
- @contact = Ppl::Entity::Contact.new
7
- @color = double(Ppl::Adapter::Color)
8
- @format.color_adapter = @color
4
+ describe "#initialize" do
5
+ it "should pass the colors through to the table" do
6
+ colors = {"number" => "blue"}
7
+ Ppl::Format::Table.should_receive(:new).with([:phone_numbers, :type], colors)
8
+ format = Ppl::Format::Contact::PhoneNumber.new(colors)
9
+ end
9
10
  end
10
11
 
11
12
  describe "#process" do
12
13
 
13
- it "should return an empty string if the contact lacks a phone number" do
14
- @format.process(Ppl::Entity::Contact.new).should eq ""
14
+ before(:each) do
15
+ @contact = Ppl::Entity::Contact.new
16
+ @number = Ppl::Entity::PhoneNumber.new("01234567890")
17
+ @format = Ppl::Format::Contact::PhoneNumber.new
18
+ @table = double(Ppl::Format::Table)
19
+ @format.table = @table
20
+ @contact.phone_numbers << @number
15
21
  end
16
22
 
17
- it "should return the contact's phone number if it is set" do
18
- @contact.phone_numbers.push("0123456789")
19
- @format.process(@contact).should eq "0123456789"
23
+ it "should always include the phone number" do
24
+ @table.should_receive(:add_row).with({
25
+ :phone_numbers => "01234567890",
26
+ :type => nil,
27
+ })
28
+ @format.process(@contact)
20
29
  end
21
30
 
22
- it "should colorize the string if configured to do so" do
23
- @format.colors = { "phone_numbers" => "blue" }
24
- @color.should_receive(:colorize).and_return("phone numbers in blue")
25
- @format.process(@contact).should eq "phone numbers in blue"
31
+ it "should put the type in parentheses" do
32
+ @number.type = "work"
33
+ @table.should_receive(:add_row).with({
34
+ :phone_numbers => "01234567890",
35
+ :type => "(work)",
36
+ })
37
+ @format.process(@contact)
26
38
  end
27
39
 
28
40
  end
29
41
 
30
42
  end
31
43
 
44
+
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: 1.20.0
4
+ version: 1.21.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-04-19 00:00:00.000000000 Z
11
+ date: 2013-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored
@@ -214,6 +214,7 @@ files:
214
214
  - lib/ppl/command/version.rb
215
215
  - lib/ppl/entity/address_book.rb
216
216
  - lib/ppl/entity/contact.rb
217
+ - lib/ppl/entity/phone_number.rb
217
218
  - lib/ppl/entity/postal_address.rb
218
219
  - lib/ppl/error/completion_not_found.rb
219
220
  - lib/ppl/error/contact_not_found.rb
@@ -288,6 +289,7 @@ files:
288
289
  - spec/ppl/command/version_spec.rb
289
290
  - spec/ppl/entity/address_book_spec.rb
290
291
  - spec/ppl/entity/contact_spec.rb
292
+ - spec/ppl/entity/phone_number_spec.rb
291
293
  - spec/ppl/entity/postal_address_spec.rb
292
294
  - spec/ppl/format/address_book/ages_spec.rb
293
295
  - spec/ppl/format/address_book/birthdays_spec.rb