ppl 1.24.0 → 1.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/completions/bash +1 -1
- data/lib/ppl/application/bootstrap.rb +15 -1
- data/lib/ppl/application/configuration.rb +4 -0
- data/lib/ppl/command/email.rb +14 -1
- data/lib/ppl/command/ls.rb +33 -3
- data/lib/ppl/format/custom/contact.rb +55 -0
- data/lib/ppl/format/custom/email_address.rb +15 -0
- data/lib/ppl/format/custom/phone_number.rb +19 -0
- data/lib/ppl/format/custom.rb +61 -0
- data/lib/ppl.rb +5 -1
- data/ppl.gemspec +2 -2
- data/spec/ppl/command/email_spec.rb +13 -0
- data/spec/ppl/command/ls_spec.rb +30 -4
- data/spec/ppl/format/custom/contact_spec.rb +102 -0
- data/spec/ppl/format/custom/email_address_spec.rb +33 -0
- data/spec/ppl/format/custom/phone_number_spec.rb +41 -0
- data/spec/ppl/format/custom_spec.rb +50 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3438ed54b9c4ab282ccc9a9389511777516fee7a
|
4
|
+
data.tar.gz: 63d86817042ebf3a768294d394bfc3c77ff60a01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c789b838676b6d9cd50f0bcd6c0060fdd87287ed3f0dd6088c11ba5a9cd995e0306eb488bc40e2f81fe9c3c7ad91a5206f6cc586cae9f93c09d21f783ff1fec6
|
7
|
+
data.tar.gz: f48891ad62cc516d9a69a73ccfe84080b086017d8d307683e4934563786d18163f7e2b5c93ee17b2fbefae67c5485598cefbf8846fb001a5756b9f594da22f55
|
data/completions/bash
CHANGED
@@ -41,6 +41,7 @@ class Ppl::Application::Bootstrap
|
|
41
41
|
email.storage = storage_adapter
|
42
42
|
email.list_format = format_address_book_email_addresses
|
43
43
|
email.show_format = format_contact_email_addresses
|
44
|
+
email.custom_format = format_email_address_custom
|
44
45
|
email
|
45
46
|
end
|
46
47
|
|
@@ -59,7 +60,8 @@ class Ppl::Application::Bootstrap
|
|
59
60
|
register :command_ls do
|
60
61
|
ls = Ppl::Command::Ls.new
|
61
62
|
ls.storage = storage_adapter
|
62
|
-
ls.
|
63
|
+
ls.default_format = format_address_book_one_line
|
64
|
+
ls.custom_format = format_contact_custom
|
63
65
|
ls
|
64
66
|
end
|
65
67
|
|
@@ -278,6 +280,18 @@ class Ppl::Application::Bootstrap
|
|
278
280
|
Ppl::Format::Contact::Birthday.new(colors)
|
279
281
|
end
|
280
282
|
|
283
|
+
register :format_contact_custom do
|
284
|
+
custom = Ppl::Format::Custom::Contact.new
|
285
|
+
custom.preset_formats = configuration.pretty
|
286
|
+
custom
|
287
|
+
end
|
288
|
+
|
289
|
+
register :format_email_address_custom do
|
290
|
+
custom = Ppl::Format::Custom::EmailAddress.new
|
291
|
+
custom.preset_formats = configuration.pretty
|
292
|
+
custom
|
293
|
+
end
|
294
|
+
|
281
295
|
register :format_contact_email_addresses do
|
282
296
|
colors = configuration.command_colors("email")
|
283
297
|
Ppl::Format::Contact::EmailAddresses.new(colors)
|
data/lib/ppl/command/email.rb
CHANGED
@@ -7,6 +7,7 @@ class Ppl::Command::Email < Ppl::Application::Command
|
|
7
7
|
attr_writer :email_service
|
8
8
|
attr_writer :list_format
|
9
9
|
attr_writer :show_format
|
10
|
+
attr_writer :custom_format
|
10
11
|
|
11
12
|
def options(parser, options)
|
12
13
|
parser.banner = "usage: ppl email <contact> [<email-address>]"
|
@@ -19,6 +20,9 @@ class Ppl::Command::Email < Ppl::Application::Command
|
|
19
20
|
parser.on("-P", "--not-preferred", "mark address as not preferred") do
|
20
21
|
options[:preferred] = false
|
21
22
|
end
|
23
|
+
parser.on("--format <format>", "specify a custom output format") do |f|
|
24
|
+
options[:format] = f
|
25
|
+
end
|
22
26
|
end
|
23
27
|
|
24
28
|
def execute(input, output)
|
@@ -48,7 +52,7 @@ class Ppl::Command::Email < Ppl::Application::Command
|
|
48
52
|
|
49
53
|
def show_contact_email_addresses(input, output)
|
50
54
|
contact = @storage.require_contact(input.arguments[0])
|
51
|
-
output.line(
|
55
|
+
output.line(format_contact(contact, input.options))
|
52
56
|
end
|
53
57
|
|
54
58
|
def remove_email_address_from_contact(input, output)
|
@@ -69,5 +73,14 @@ class Ppl::Command::Email < Ppl::Application::Command
|
|
69
73
|
(contact.email_addresses.select { |ea| ea.address == email_address }).empty?
|
70
74
|
end
|
71
75
|
|
76
|
+
def format_contact(contact, options)
|
77
|
+
if options[:format].nil?
|
78
|
+
@show_format.process(contact)
|
79
|
+
else
|
80
|
+
@custom_format.format = options[:format]
|
81
|
+
contact.email_addresses.map { |e| @custom_format.process(e) }.join("\n")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
72
85
|
end
|
73
86
|
|
data/lib/ppl/command/ls.rb
CHANGED
@@ -4,17 +4,47 @@ class Ppl::Command::Ls < Ppl::Application::Command
|
|
4
4
|
name "ls"
|
5
5
|
description "List all contacts"
|
6
6
|
|
7
|
-
attr_writer :
|
7
|
+
attr_writer :default_format
|
8
|
+
attr_writer :custom_format
|
8
9
|
|
9
10
|
def options(parser, options)
|
10
11
|
parser.banner = "usage: ppl ls"
|
12
|
+
parser.on("--format <format>", "specify a custom output format") do |format|
|
13
|
+
options[:format] = format
|
14
|
+
end
|
15
|
+
parser.on("--pretty <format>", "specify a custom output format") do |pretty|
|
16
|
+
options[:pretty] = pretty
|
17
|
+
end
|
11
18
|
end
|
12
19
|
|
13
20
|
def execute(input, output)
|
14
21
|
address_book = @storage.load_address_book
|
15
|
-
formatted =
|
22
|
+
formatted = format_address_book(address_book, input.options)
|
16
23
|
output.line(formatted)
|
17
|
-
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def format_address_book(address_book, options)
|
30
|
+
if custom_formatting? options
|
31
|
+
use_custom_format(address_book, options)
|
32
|
+
else
|
33
|
+
@default_format.process(address_book)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def custom_formatting?(options)
|
38
|
+
options[:pretty] || options[:format]
|
39
|
+
end
|
40
|
+
|
41
|
+
def use_custom_format(address_book, options)
|
42
|
+
if !options[:pretty].nil?
|
43
|
+
@custom_format.use_preset options[:pretty]
|
44
|
+
elsif !options[:format].nil?
|
45
|
+
@custom_format.format = options[:format]
|
46
|
+
end
|
47
|
+
address_book.contacts.map { |c| @custom_format.process(c) }.join("\n")
|
18
48
|
end
|
19
49
|
|
20
50
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
|
2
|
+
class Ppl::Format::Custom::Contact < Ppl::Format::Custom
|
3
|
+
|
4
|
+
format :n do |anything|
|
5
|
+
"\n"
|
6
|
+
end
|
7
|
+
|
8
|
+
format :i do |contact|
|
9
|
+
contact.id
|
10
|
+
end
|
11
|
+
|
12
|
+
format :N do |contact|
|
13
|
+
contact.name
|
14
|
+
end
|
15
|
+
|
16
|
+
format :a do |contact|
|
17
|
+
contact.age(Date.today)
|
18
|
+
end
|
19
|
+
|
20
|
+
format :b do |contact|
|
21
|
+
unless contact.birthday.nil?
|
22
|
+
contact.birthday.strftime("%Y-%m-%d")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
format :k do |contact|
|
27
|
+
contact.nicknames.first
|
28
|
+
end
|
29
|
+
|
30
|
+
format :e do |contact|
|
31
|
+
preferred = contact.email_addresses.find { |e| e.preferred }
|
32
|
+
first = contact.email_addresses.first
|
33
|
+
if !preferred.nil?
|
34
|
+
preferred.address
|
35
|
+
elsif !first.nil?
|
36
|
+
first.address
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
format :o do |contact|
|
41
|
+
contact.organizations.first
|
42
|
+
end
|
43
|
+
|
44
|
+
format :p do |contact|
|
45
|
+
preferred = contact.phone_numbers.find { |p| p.preferred }
|
46
|
+
first = contact.phone_numbers.first
|
47
|
+
if !preferred.nil?
|
48
|
+
preferred.number
|
49
|
+
elsif !first.nil?
|
50
|
+
first.number
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
class Ppl::Format::Custom::PhoneNumber < Ppl::Format::Custom
|
3
|
+
|
4
|
+
format :n do |phone_number|
|
5
|
+
phone_number.number
|
6
|
+
end
|
7
|
+
|
8
|
+
format :t do |phone_number|
|
9
|
+
phone_number.type
|
10
|
+
end
|
11
|
+
|
12
|
+
format :f do |phone_number|
|
13
|
+
if phone_number.preferred
|
14
|
+
"*"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
|
2
|
+
class Ppl::Format::Custom
|
3
|
+
|
4
|
+
attr_accessor :format
|
5
|
+
attr_accessor :preset_formats
|
6
|
+
|
7
|
+
def self.format(symbol, &block)
|
8
|
+
@format_blocks ||= {}
|
9
|
+
@format_blocks[symbol] = block
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.process(key, object)
|
13
|
+
if @format_blocks[key]
|
14
|
+
@format_blocks[key][object]
|
15
|
+
else
|
16
|
+
key
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(format = nil)
|
21
|
+
@format = format
|
22
|
+
end
|
23
|
+
|
24
|
+
def process(object)
|
25
|
+
@object = object
|
26
|
+
string_pieces = @format.scan(/[^%]+|%-?\d*./)
|
27
|
+
string_pieces.map(&method(:process_piece)).join
|
28
|
+
end
|
29
|
+
|
30
|
+
def use_preset(format_name)
|
31
|
+
@format = @preset_formats[format_name]
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def process_piece(string)
|
37
|
+
matches = string.scan(/^%(-?\d+)?([a-z])$/i)
|
38
|
+
if !matches.empty?
|
39
|
+
output = generate_output(matches[0][1].to_sym)
|
40
|
+
pad_output(output, matches[0][0].to_i)
|
41
|
+
else
|
42
|
+
string
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def generate_output(symbol)
|
47
|
+
self.class.process(symbol, @object)
|
48
|
+
end
|
49
|
+
|
50
|
+
def pad_output(output, padding)
|
51
|
+
if padding > 0
|
52
|
+
output.to_s.rjust(padding, " ")
|
53
|
+
elsif padding < 0
|
54
|
+
output.to_s.ljust(padding.abs, " ")
|
55
|
+
else
|
56
|
+
output
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
data/lib/ppl.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module Ppl
|
3
3
|
|
4
|
-
Version = "1.
|
4
|
+
Version = "1.25.0"
|
5
5
|
|
6
6
|
module Adapter
|
7
7
|
end
|
@@ -104,6 +104,10 @@ require "ppl/format/contact/organization"
|
|
104
104
|
require "ppl/format/contact/phone_number"
|
105
105
|
require "ppl/format/contact/postal_address"
|
106
106
|
require "ppl/format/contact/urls"
|
107
|
+
require "ppl/format/custom"
|
108
|
+
require "ppl/format/custom/contact"
|
109
|
+
require "ppl/format/custom/email_address"
|
110
|
+
require "ppl/format/custom/phone_number"
|
107
111
|
require "ppl/format/postal_address"
|
108
112
|
require "ppl/format/postal_address/one_line"
|
109
113
|
require "ppl/format/table"
|
data/ppl.gemspec
CHANGED
@@ -21,12 +21,14 @@ describe Ppl::Command::Email do
|
|
21
21
|
@output = double(Ppl::Application::Output)
|
22
22
|
@list_format = double(Ppl::Format::AddressBook)
|
23
23
|
@show_format = double(Ppl::Format::Contact)
|
24
|
+
@custom_format = double(Ppl::Format::Custom)
|
24
25
|
@storage.stub(:require_contact).and_return(@contact)
|
25
26
|
@storage.stub(:save_contact)
|
26
27
|
@command.storage = @storage
|
27
28
|
@command.email_service = @service
|
28
29
|
@command.list_format = @list_format
|
29
30
|
@command.show_format = @show_format
|
31
|
+
@command.custom_format = @custom_format
|
30
32
|
end
|
31
33
|
|
32
34
|
it "should list all email addresses by default" do
|
@@ -43,6 +45,17 @@ describe Ppl::Command::Email do
|
|
43
45
|
@output.should_receive(:line).with("imagine this is a list")
|
44
46
|
@command.execute(@input, @output)
|
45
47
|
end
|
48
|
+
|
49
|
+
it "should output addresses in a custom format if one is given" do
|
50
|
+
@input.arguments << "jdoe"
|
51
|
+
@input.options[:format] = "%e"
|
52
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("jdoe@example.org")
|
53
|
+
@storage.should_receive(:require_contact).and_return(@contact)
|
54
|
+
@custom_format.should_receive(:format=).with("%e")
|
55
|
+
@custom_format.should_receive(:process).and_return("")
|
56
|
+
@output.should_receive(:line).with("")
|
57
|
+
@command.execute(@input, @output)
|
58
|
+
end
|
46
59
|
|
47
60
|
it "should delegate to the service layer to add a new email address" do
|
48
61
|
@input.arguments = ["jdoe", "jdoe@example.org"]
|
data/spec/ppl/command/ls_spec.rb
CHANGED
@@ -7,10 +7,12 @@ describe Ppl::Command::Ls do
|
|
7
7
|
@output = double(Ppl::Application::Output)
|
8
8
|
@storage = double(Ppl::Adapter::Storage)
|
9
9
|
@format = double(Ppl::Format::AddressBook)
|
10
|
+
@custom = double(Ppl::Format::Custom)
|
10
11
|
@address_book = double(Ppl::Entity::AddressBook)
|
11
12
|
|
12
|
-
@command.
|
13
|
-
@command.
|
13
|
+
@command.custom_format = @custom
|
14
|
+
@command.default_format = @format
|
15
|
+
@command.storage = @storage
|
14
16
|
end
|
15
17
|
|
16
18
|
describe "#name" do
|
@@ -20,12 +22,36 @@ describe Ppl::Command::Ls do
|
|
20
22
|
end
|
21
23
|
|
22
24
|
describe "#execute" do
|
23
|
-
|
25
|
+
|
26
|
+
before(:each) do
|
24
27
|
@storage.should_receive(:load_address_book).and_return(@address_book)
|
28
|
+
end
|
29
|
+
|
30
|
+
after(:each) do
|
31
|
+
@command.execute(@input, @output)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should show the list of contacts in the address book" do
|
25
35
|
@format.should_receive(:process).and_return("list of contacts")
|
26
36
|
@output.should_receive(:line).with("list of contacts")
|
27
|
-
@command.execute(@input, @output)
|
28
37
|
end
|
38
|
+
|
39
|
+
it "should let the user specify a preset pretty format" do
|
40
|
+
@input.options[:pretty] = "test"
|
41
|
+
@address_book.should_receive(:contacts).and_return([1])
|
42
|
+
@custom.should_receive(:use_preset).with("test")
|
43
|
+
@custom.should_receive(:process).and_return("list of contacts")
|
44
|
+
@output.should_receive(:line).with("list of contacts")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should let the user specify a custom format" do
|
48
|
+
@input.options[:format] = "%n"
|
49
|
+
@address_book.should_receive(:contacts).and_return([1])
|
50
|
+
@custom.should_receive(:format=).with("%n")
|
51
|
+
@custom.should_receive(:process).and_return("list of contacts")
|
52
|
+
@output.should_receive(:line).with("list of contacts")
|
53
|
+
end
|
54
|
+
|
29
55
|
end
|
30
56
|
|
31
57
|
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
|
2
|
+
describe Ppl::Format::Custom::Contact do
|
3
|
+
|
4
|
+
before(:each) do
|
5
|
+
@format = Ppl::Format::Custom::Contact.new
|
6
|
+
@contact = Ppl::Entity::Contact.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "%n" do
|
10
|
+
it "should be replaced with a newlines" do
|
11
|
+
@format.format = "%n"
|
12
|
+
@format.process(@contact).should eq "\n"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "%i" do
|
17
|
+
it "should output the contact's ID" do
|
18
|
+
@contact.id = "test"
|
19
|
+
@format.format = "%i"
|
20
|
+
@format.process(@contact).should eq "test"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "%N" do
|
25
|
+
it "should output the contact's name" do
|
26
|
+
@contact.name = "John Doe"
|
27
|
+
@format.format = "%N"
|
28
|
+
@format.process(@contact).should eq "John Doe"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "%k" do
|
33
|
+
it "should output the contact's nickname" do
|
34
|
+
@contact.nicknames << "Johnny"
|
35
|
+
@format.format = "%k"
|
36
|
+
@format.process(@contact).should eq "Johnny"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "%a" do
|
41
|
+
it "should output the contact's age" do
|
42
|
+
@contact.birthday = Date.parse("2000-01-01")
|
43
|
+
Date.stub(:today).and_return(Date.parse("2010-01-02"))
|
44
|
+
@format.format = "%a"
|
45
|
+
@format.process(@contact).should eq "10"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "%b" do
|
50
|
+
it "should output the contact's birthday" do
|
51
|
+
@contact.birthday = Date.parse("1985-06-07")
|
52
|
+
@format.format = "%b"
|
53
|
+
@format.process(@contact).should eq "1985-06-07"
|
54
|
+
end
|
55
|
+
it "should cause no errors if there's no birthday" do
|
56
|
+
@contact.birthday = nil
|
57
|
+
@format.format = "%b"
|
58
|
+
@format.process(@contact).should eq ""
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "%e" do
|
63
|
+
before(:each) do
|
64
|
+
@format.format = "%e"
|
65
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("a@example.org")
|
66
|
+
@contact.email_addresses << Ppl::Entity::EmailAddress.new("b@example.org")
|
67
|
+
end
|
68
|
+
it "should output the first email address" do
|
69
|
+
@format.process(@contact).should eq "a@example.org"
|
70
|
+
end
|
71
|
+
it "should output the preferred email address" do
|
72
|
+
@contact.email_addresses[1].preferred = true
|
73
|
+
@format.process(@contact).should eq "b@example.org"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "%p" do
|
78
|
+
before(:each) do
|
79
|
+
@format.format = "%p"
|
80
|
+
@contact.phone_numbers << Ppl::Entity::PhoneNumber.new("0123456789")
|
81
|
+
@contact.phone_numbers << Ppl::Entity::PhoneNumber.new("1098765432")
|
82
|
+
end
|
83
|
+
it "should output the first phone number" do
|
84
|
+
@format.process(@contact).should eq "0123456789"
|
85
|
+
end
|
86
|
+
it "should output the preferred phone number" do
|
87
|
+
@contact.phone_numbers[1].preferred = true
|
88
|
+
@format.process(@contact).should eq "1098765432"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "%o" do
|
93
|
+
it "should output the contact's organization" do
|
94
|
+
@contact.organizations << "WTF Inc"
|
95
|
+
@format.format = "%o"
|
96
|
+
@format.process(@contact).should eq "WTF Inc"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
describe Ppl::Format::Custom::EmailAddress do
|
3
|
+
|
4
|
+
before(:each) do
|
5
|
+
@format = Ppl::Format::Custom::EmailAddress.new
|
6
|
+
@address = Ppl::Entity::EmailAddress.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "%a" do
|
10
|
+
it "should output the address" do
|
11
|
+
@address.address = "test@example.org"
|
12
|
+
@format.format = "<%a>"
|
13
|
+
@format.process(@address).should eq "<test@example.org>"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "%f" do
|
18
|
+
before(:each) do
|
19
|
+
@format.format = "%f"
|
20
|
+
end
|
21
|
+
it "should output a star if the address is preferred" do
|
22
|
+
@address.preferred = true
|
23
|
+
@format.process(@address).should eq "*"
|
24
|
+
end
|
25
|
+
it "should output nothing if the address is not preferred" do
|
26
|
+
@address.preferred = false
|
27
|
+
@format.process(@address).should eq ""
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
describe Ppl::Format::Custom::PhoneNumber do
|
3
|
+
|
4
|
+
before(:each) do
|
5
|
+
@format = Ppl::Format::Custom::PhoneNumber.new
|
6
|
+
@number = Ppl::Entity::PhoneNumber.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "%n" do
|
10
|
+
it "should output the number itself" do
|
11
|
+
@number.number = "1234567890"
|
12
|
+
@format.format = "tel: %n"
|
13
|
+
@format.process(@number).should eq "tel: 1234567890"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "%t" do
|
18
|
+
it "should output the type of the number" do
|
19
|
+
@number.type = "cell"
|
20
|
+
@format.format = "(%t)"
|
21
|
+
@format.process(@number).should eq "(cell)"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "%f" do
|
26
|
+
before(:each) do
|
27
|
+
@format.format = "%f"
|
28
|
+
end
|
29
|
+
it "should output a star if the number is preferred" do
|
30
|
+
@number.preferred = true
|
31
|
+
@format.process(@number).should eq "*"
|
32
|
+
end
|
33
|
+
it "should output nothing if the number is not preferred" do
|
34
|
+
@number.preferred = false
|
35
|
+
@format.process(@number).should eq ""
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
describe "Ppl::Format::Custom" do
|
3
|
+
|
4
|
+
describe "::format" do
|
5
|
+
it "should accept a symbol and a block" do
|
6
|
+
Ppl::Format::Custom::format :N do |h| h[:name] end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "::process" do
|
11
|
+
it "should use the block passed to ::format to process the object" do
|
12
|
+
Ppl::Format::Custom::process(:N, {:name => "jdoe"}).should eq "jdoe"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#initialize" do
|
17
|
+
it "should accept a format string" do
|
18
|
+
Ppl::Format::Custom.new("%N").format.should eq "%N"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#process" do
|
23
|
+
it "should convert the given object into a string based on the format" do
|
24
|
+
custom = Ppl::Format::Custom.new("%N %N %N")
|
25
|
+
object = { :name => "jdoe" }
|
26
|
+
custom.process(object).should eq "jdoe jdoe jdoe"
|
27
|
+
end
|
28
|
+
it "should pad with leading spaces if a positive width is given" do
|
29
|
+
custom = Ppl::Format::Custom.new("%10N")
|
30
|
+
object = { :name => "jdoe" }
|
31
|
+
custom.process(object).should eq " jdoe"
|
32
|
+
end
|
33
|
+
it "should pad with trailing spaces if a negative width is given" do
|
34
|
+
custom = Ppl::Format::Custom.new("%-10N")
|
35
|
+
object = { :name => "jdoe" }
|
36
|
+
custom.process(object).should eq "jdoe "
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#use_preset" do
|
41
|
+
it "should set the format string to the preset with the given name" do
|
42
|
+
custom = Ppl::Format::Custom.new
|
43
|
+
custom.preset_formats = { "example" => "%N (%N)" }
|
44
|
+
custom.use_preset "example"
|
45
|
+
custom.process({:name => "a"}).should eq "a (a)"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
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.
|
4
|
+
version: 1.25.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-
|
11
|
+
date: 2013-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colored
|
@@ -255,6 +255,10 @@ files:
|
|
255
255
|
- lib/ppl/format/contact/phone_number.rb
|
256
256
|
- lib/ppl/format/contact/postal_address.rb
|
257
257
|
- lib/ppl/format/contact/urls.rb
|
258
|
+
- lib/ppl/format/custom.rb
|
259
|
+
- lib/ppl/format/custom/contact.rb
|
260
|
+
- lib/ppl/format/custom/email_address.rb
|
261
|
+
- lib/ppl/format/custom/phone_number.rb
|
258
262
|
- lib/ppl/format/postal_address.rb
|
259
263
|
- lib/ppl/format/postal_address/one_line.rb
|
260
264
|
- lib/ppl/format/table.rb
|
@@ -330,6 +334,10 @@ files:
|
|
330
334
|
- spec/ppl/format/contact/postal_address_spec.rb
|
331
335
|
- spec/ppl/format/contact/urls_spec.rb
|
332
336
|
- spec/ppl/format/contact_spec.rb
|
337
|
+
- spec/ppl/format/custom/contact_spec.rb
|
338
|
+
- spec/ppl/format/custom/email_address_spec.rb
|
339
|
+
- spec/ppl/format/custom/phone_number_spec.rb
|
340
|
+
- spec/ppl/format/custom_spec.rb
|
333
341
|
- spec/ppl/format/postal_address/one_line_spec.rb
|
334
342
|
- spec/ppl/format/postal_address_spec.rb
|
335
343
|
- spec/ppl/format/table_spec.rb
|