ppl 1.14.1 → 1.15.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/Gemfile.lock +3 -1
- data/lib/ppl/adapter/color/colored.rb +15 -0
- data/lib/ppl/adapter/color.rb +9 -0
- data/lib/ppl/application/bootstrap.rb +309 -61
- data/lib/ppl/application/configuration.rb +15 -0
- data/lib/ppl/command/age.rb +0 -5
- data/lib/ppl/command/bday.rb +0 -5
- data/lib/ppl/command/email.rb +1 -3
- data/lib/ppl/command/ls.rb +0 -5
- data/lib/ppl/command/mutt.rb +0 -4
- data/lib/ppl/command/name.rb +0 -5
- data/lib/ppl/command/nick.rb +1 -3
- data/lib/ppl/command/org.rb +1 -3
- data/lib/ppl/command/phone.rb +1 -3
- data/lib/ppl/command/post.rb +0 -5
- data/lib/ppl/command/url.rb +1 -3
- data/lib/ppl/format/address_book/ages.rb +2 -4
- data/lib/ppl/format/address_book/birthdays.rb +2 -2
- data/lib/ppl/format/address_book/email_addresses.rb +3 -3
- data/lib/ppl/format/address_book/names.rb +2 -2
- data/lib/ppl/format/address_book/nicknames.rb +2 -2
- data/lib/ppl/format/address_book/one_line.rb +2 -2
- data/lib/ppl/format/address_book/organizations.rb +2 -2
- data/lib/ppl/format/address_book/phone_numbers.rb +2 -2
- data/lib/ppl/format/address_book/postal_addresses.rb +2 -2
- data/lib/ppl/format/address_book/urls.rb +2 -2
- data/lib/ppl/format/contact/age.rb +13 -1
- data/lib/ppl/format/contact/birthday.rb +11 -0
- data/lib/ppl/format/contact/email_addresses.rb +19 -1
- data/lib/ppl/format/contact/name.rb +18 -2
- data/lib/ppl/format/contact/nicknames.rb +19 -1
- data/lib/ppl/format/contact/organization.rb +19 -1
- data/lib/ppl/format/contact/phone_number.rb +19 -1
- data/lib/ppl/format/contact/urls.rb +19 -1
- data/lib/ppl/format/table.rb +15 -6
- data/lib/ppl.rb +3 -1
- data/ppl.gemspec +4 -2
- data/spec/ppl/adapter/color/colored_spec.rb +24 -0
- data/spec/ppl/adapter/color_spec.rb +15 -0
- data/spec/ppl/application/bootstrap_spec.rb +403 -25
- data/spec/ppl/application/configuration_spec.rb +46 -0
- data/spec/ppl/command/mutt_spec.rb +4 -0
- data/spec/ppl/format/address_book/ages_spec.rb +10 -0
- data/spec/ppl/format/address_book/birthdays_spec.rb +10 -0
- data/spec/ppl/format/address_book/email_addresses_spec.rb +12 -2
- data/spec/ppl/format/address_book/names_spec.rb +10 -0
- data/spec/ppl/format/address_book/nicknames_spec.rb +10 -0
- data/spec/ppl/format/address_book/one_line_spec.rb +10 -0
- data/spec/ppl/format/address_book/organizations_spec.rb +10 -0
- data/spec/ppl/format/address_book/phone_numbers_spec.rb +10 -0
- data/spec/ppl/format/address_book/postal_addresses_spec.rb +10 -0
- data/spec/ppl/format/address_book/urls_spec.rb +10 -0
- data/spec/ppl/format/contact/age_spec.rb +10 -0
- data/spec/ppl/format/contact/birthday_spec.rb +8 -0
- data/spec/ppl/format/contact/email_addresses_spec.rb +8 -0
- data/spec/ppl/format/contact/name_spec.rb +8 -0
- data/spec/ppl/format/contact/nicknames_spec.rb +8 -0
- data/spec/ppl/format/contact/organization_spec.rb +8 -0
- data/spec/ppl/format/contact/phone_number_spec.rb +8 -0
- data/spec/ppl/format/contact/urls_spec.rb +8 -0
- data/spec/ppl/format/table_spec.rb +20 -0
- metadata +38 -2
@@ -3,8 +3,8 @@ class Ppl::Format::AddressBook::EmailAddresses < Ppl::Format::AddressBook
|
|
3
3
|
|
4
4
|
attr_writer :table
|
5
5
|
|
6
|
-
def initialize
|
7
|
-
@table = Ppl::Format::Table.new([:
|
6
|
+
def initialize(colors={})
|
7
|
+
@table = Ppl::Format::Table.new([:id, :email_addresses], colors)
|
8
8
|
end
|
9
9
|
|
10
10
|
def process(address_book)
|
@@ -17,7 +17,7 @@ class Ppl::Format::AddressBook::EmailAddresses < Ppl::Format::AddressBook
|
|
17
17
|
|
18
18
|
def add_row(contact)
|
19
19
|
@table.add_row({
|
20
|
-
:
|
20
|
+
:id => sprintf("%s:", contact.id),
|
21
21
|
:email_addresses => contact.email_addresses.join(", "),
|
22
22
|
})
|
23
23
|
end
|
@@ -3,8 +3,8 @@ class Ppl::Format::AddressBook::Names < Ppl::Format::AddressBook
|
|
3
3
|
|
4
4
|
attr_writer :table
|
5
5
|
|
6
|
-
def initialize
|
7
|
-
@table = Ppl::Format::Table.new([:id, :name])
|
6
|
+
def initialize(colors={})
|
7
|
+
@table = Ppl::Format::Table.new([:id, :name], colors)
|
8
8
|
end
|
9
9
|
|
10
10
|
def process(address_book)
|
@@ -3,8 +3,8 @@ class Ppl::Format::AddressBook::Nicknames < Ppl::Format::AddressBook
|
|
3
3
|
|
4
4
|
attr_writer :table
|
5
5
|
|
6
|
-
def initialize
|
7
|
-
@table = Ppl::Format::Table.new([:id, :nicknames])
|
6
|
+
def initialize(colors={})
|
7
|
+
@table = Ppl::Format::Table.new([:id, :nicknames], colors)
|
8
8
|
end
|
9
9
|
|
10
10
|
def process(address_book)
|
@@ -3,8 +3,8 @@ class Ppl::Format::AddressBook::OneLine < Ppl::Format::AddressBook
|
|
3
3
|
|
4
4
|
attr_writer :table
|
5
5
|
|
6
|
-
def initialize
|
7
|
-
@table = Ppl::Format::Table.new([:id, :name, :email])
|
6
|
+
def initialize(colors={})
|
7
|
+
@table = Ppl::Format::Table.new([:id, :name, :email], colors)
|
8
8
|
end
|
9
9
|
|
10
10
|
def process(address_book)
|
@@ -3,8 +3,8 @@ class Ppl::Format::AddressBook::Organizations < Ppl::Format::AddressBook
|
|
3
3
|
|
4
4
|
attr_writer :table
|
5
5
|
|
6
|
-
def initialize
|
7
|
-
@table = Ppl::Format::Table.new([:id, :organizations])
|
6
|
+
def initialize(colors={})
|
7
|
+
@table = Ppl::Format::Table.new([:id, :organizations], colors)
|
8
8
|
end
|
9
9
|
|
10
10
|
def process(address_book)
|
@@ -3,8 +3,8 @@ class Ppl::Format::AddressBook::PhoneNumbers < Ppl::Format::AddressBook
|
|
3
3
|
|
4
4
|
attr_writer :table
|
5
5
|
|
6
|
-
def initialize
|
7
|
-
@table = Ppl::Format::Table.new([:id, :phone_numbers])
|
6
|
+
def initialize(colors={})
|
7
|
+
@table = Ppl::Format::Table.new([:id, :phone_numbers], colors)
|
8
8
|
end
|
9
9
|
|
10
10
|
def process(address_book)
|
@@ -3,8 +3,8 @@ class Ppl::Format::AddressBook::PostalAddresses < Ppl::Format::AddressBook
|
|
3
3
|
|
4
4
|
attr_writer :table
|
5
5
|
|
6
|
-
def initialize
|
7
|
-
@table = Ppl::Format::Table.new([:id, :postal_address])
|
6
|
+
def initialize(colors={})
|
7
|
+
@table = Ppl::Format::Table.new([:id, :postal_address], colors)
|
8
8
|
end
|
9
9
|
|
10
10
|
def process(address_book)
|
@@ -3,8 +3,8 @@ class Ppl::Format::AddressBook::Urls < Ppl::Format::AddressBook
|
|
3
3
|
|
4
4
|
attr_writer :table
|
5
5
|
|
6
|
-
def initialize
|
7
|
-
@table = Ppl::Format::Table.new([:id, :urls])
|
6
|
+
def initialize(colors={})
|
7
|
+
@table = Ppl::Format::Table.new([:id, :urls], colors)
|
8
8
|
end
|
9
9
|
|
10
10
|
def process(address_book)
|
@@ -1,8 +1,20 @@
|
|
1
1
|
|
2
2
|
class Ppl::Format::Contact::Age < Ppl::Format::Contact
|
3
3
|
|
4
|
+
attr_writer :color_adapter
|
5
|
+
attr_writer :colors
|
6
|
+
|
7
|
+
def initialize(colors={})
|
8
|
+
@colors = colors
|
9
|
+
@color_adapter = Ppl::Adapter::Color::Colored.new
|
10
|
+
end
|
11
|
+
|
4
12
|
def process(contact)
|
5
|
-
contact.age(Date.today).to_s
|
13
|
+
age = contact.age(Date.today).to_s
|
14
|
+
if @colors["age"]
|
15
|
+
age = @color_adapter.colorize(age, @colors["age"])
|
16
|
+
end
|
17
|
+
age
|
6
18
|
end
|
7
19
|
|
8
20
|
end
|
@@ -1,11 +1,22 @@
|
|
1
1
|
|
2
2
|
class Ppl::Format::Contact::Birthday < Ppl::Format::Contact
|
3
3
|
|
4
|
+
attr_writer :color_adapter
|
5
|
+
attr_writer :colors
|
6
|
+
|
7
|
+
def initialize(colors={})
|
8
|
+
@colors = colors
|
9
|
+
@color_adapter = Ppl::Adapter::Color::Colored.new
|
10
|
+
end
|
11
|
+
|
4
12
|
def process(contact)
|
5
13
|
output = ""
|
6
14
|
if !contact.birthday.nil?
|
7
15
|
output += contact.birthday.strftime("%Y-%m-%d")
|
8
16
|
end
|
17
|
+
if @colors["birthday"]
|
18
|
+
output = @color_adapter.colorize(output, @colors["birthday"])
|
19
|
+
end
|
9
20
|
return output
|
10
21
|
end
|
11
22
|
|
@@ -1,12 +1,30 @@
|
|
1
1
|
|
2
2
|
class Ppl::Format::Contact::EmailAddresses < Ppl::Format::Contact
|
3
3
|
|
4
|
+
attr_writer :color_adapter
|
5
|
+
attr_writer :colors
|
6
|
+
|
7
|
+
def initialize(colors={})
|
8
|
+
@colors = colors
|
9
|
+
@color_adapter = Ppl::Adapter::Color::Colored.new
|
10
|
+
end
|
11
|
+
|
4
12
|
def process(contact)
|
5
13
|
lines = []
|
6
14
|
contact.email_addresses.each do |email_address|
|
7
15
|
lines.push email_address
|
8
16
|
end
|
9
|
-
lines.join("\n")
|
17
|
+
colorize_output(lines.join("\n"))
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def colorize_output(string)
|
23
|
+
if @colors["email_addresses"]
|
24
|
+
@color_adapter.colorize(string, @colors["email_addresses"])
|
25
|
+
else
|
26
|
+
string
|
27
|
+
end
|
10
28
|
end
|
11
29
|
|
12
30
|
end
|
@@ -1,14 +1,30 @@
|
|
1
1
|
|
2
2
|
class Ppl::Format::Contact::Name < Ppl::Format::Contact
|
3
3
|
|
4
|
+
attr_writer :color_adapter
|
5
|
+
attr_writer :colors
|
6
|
+
|
7
|
+
def initialize(colors={})
|
8
|
+
@colors = colors
|
9
|
+
@color_adapter = Ppl::Adapter::Color::Colored.new
|
10
|
+
end
|
11
|
+
|
4
12
|
def process(contact)
|
5
13
|
output = ""
|
6
|
-
|
7
14
|
if !contact.name.nil?
|
8
15
|
output += contact.name
|
9
16
|
end
|
17
|
+
colorize_output(output)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
10
21
|
|
11
|
-
|
22
|
+
def colorize_output(string)
|
23
|
+
if @colors["name"]
|
24
|
+
@color_adapter.colorize(string, @colors["name"])
|
25
|
+
else
|
26
|
+
string
|
27
|
+
end
|
12
28
|
end
|
13
29
|
|
14
30
|
end
|
@@ -1,8 +1,26 @@
|
|
1
1
|
|
2
2
|
class Ppl::Format::Contact::Nicknames < Ppl::Format::Contact
|
3
3
|
|
4
|
+
attr_writer :color_adapter
|
5
|
+
attr_writer :colors
|
6
|
+
|
7
|
+
def initialize(colors={})
|
8
|
+
@colors = colors
|
9
|
+
@color_adapter = Ppl::Adapter::Color::Colored.new
|
10
|
+
end
|
11
|
+
|
4
12
|
def process(contact)
|
5
|
-
contact.nicknames.join("\n")
|
13
|
+
colorize_output(contact.nicknames.join("\n"))
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def colorize_output(string)
|
19
|
+
if @colors["nicknames"]
|
20
|
+
@color_adapter.colorize(string, @colors["nicknames"])
|
21
|
+
else
|
22
|
+
string
|
23
|
+
end
|
6
24
|
end
|
7
25
|
|
8
26
|
end
|
@@ -1,8 +1,26 @@
|
|
1
1
|
|
2
2
|
class Ppl::Format::Contact::Organization < Ppl::Format::Contact
|
3
3
|
|
4
|
+
attr_writer :color_adapter
|
5
|
+
attr_writer :colors
|
6
|
+
|
7
|
+
def initialize(colors={})
|
8
|
+
@colors = colors
|
9
|
+
@color_adapter = Ppl::Adapter::Color::Colored.new
|
10
|
+
end
|
11
|
+
|
4
12
|
def process(contact)
|
5
|
-
contact.organizations.join("\n")
|
13
|
+
colorize_output(contact.organizations.join("\n"))
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def colorize_output(string)
|
19
|
+
if @colors["organizations"]
|
20
|
+
@color_adapter.colorize(string, @colors["organizations"])
|
21
|
+
else
|
22
|
+
string
|
23
|
+
end
|
6
24
|
end
|
7
25
|
|
8
26
|
end
|
@@ -1,8 +1,26 @@
|
|
1
1
|
|
2
2
|
class Ppl::Format::Contact::PhoneNumber < Ppl::Format::Contact
|
3
3
|
|
4
|
+
attr_writer :color_adapter
|
5
|
+
attr_writer :colors
|
6
|
+
|
7
|
+
def initialize(colors={})
|
8
|
+
@colors = colors
|
9
|
+
@color_adapter = Ppl::Adapter::Color::Colored.new
|
10
|
+
end
|
11
|
+
|
4
12
|
def process(contact)
|
5
|
-
contact.phone_numbers.join("\n")
|
13
|
+
colorize_output(contact.phone_numbers.join("\n"))
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def colorize_output(string)
|
19
|
+
if @colors["phone_numbers"]
|
20
|
+
@color_adapter.colorize(string, @colors["phone_numbers"])
|
21
|
+
else
|
22
|
+
string
|
23
|
+
end
|
6
24
|
end
|
7
25
|
|
8
26
|
end
|
@@ -1,8 +1,26 @@
|
|
1
1
|
|
2
2
|
class Ppl::Format::Contact::Urls < Ppl::Format::Contact
|
3
3
|
|
4
|
+
attr_writer :color_adapter
|
5
|
+
attr_writer :colors
|
6
|
+
|
7
|
+
def initialize(colors={})
|
8
|
+
@colors = colors
|
9
|
+
@color_adapter = Ppl::Adapter::Color::Colored.new
|
10
|
+
end
|
11
|
+
|
4
12
|
def process(contact)
|
5
|
-
contact.urls.join("\n")
|
13
|
+
colorize_output(contact.urls.join("\n"))
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def colorize_output(string)
|
19
|
+
if @colors["urls"]
|
20
|
+
@color_adapter.colorize(string, @colors["urls"])
|
21
|
+
else
|
22
|
+
string
|
23
|
+
end
|
6
24
|
end
|
7
25
|
|
8
26
|
end
|
data/lib/ppl/format/table.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
|
2
|
+
require "colored"
|
3
|
+
|
2
4
|
class Ppl::Format::Table
|
3
5
|
|
4
6
|
SEPARATOR_SPACES = 0
|
@@ -7,12 +9,14 @@ class Ppl::Format::Table
|
|
7
9
|
attr_accessor :columns
|
8
10
|
attr_accessor :rows
|
9
11
|
attr_accessor :separator
|
12
|
+
attr_accessor :colors
|
10
13
|
|
11
|
-
def initialize(columns=[])
|
14
|
+
def initialize(columns=[], colors={})
|
12
15
|
@columns = columns
|
13
16
|
@rows = []
|
14
17
|
@separator = SEPARATOR_SPACES
|
15
|
-
|
18
|
+
@colors = colors
|
19
|
+
@color_adapter = Ppl::Adapter::Color::Colored.new
|
16
20
|
@column_widths = {}
|
17
21
|
@columns.each { |c| @column_widths[c] = 0 }
|
18
22
|
end
|
@@ -44,13 +48,18 @@ class Ppl::Format::Table
|
|
44
48
|
end
|
45
49
|
|
46
50
|
def format_cell(row, column)
|
47
|
-
width
|
51
|
+
width = @column_widths[column]
|
52
|
+
string = row[column].to_s
|
48
53
|
if @separator == SEPARATOR_SPACES
|
49
|
-
string = sprintf("%-#{width}s ",
|
54
|
+
string = sprintf("%-#{width}s ", string)
|
50
55
|
else
|
51
|
-
string = sprintf("%s\t",
|
56
|
+
string = sprintf("%s\t", string)
|
52
57
|
end
|
53
|
-
|
58
|
+
colorize_string(string, column)
|
59
|
+
end
|
60
|
+
|
61
|
+
def colorize_string(string, column)
|
62
|
+
@color_adapter.colorize(string, @colors[column.to_s])
|
54
63
|
end
|
55
64
|
|
56
65
|
end
|
data/lib/ppl.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module Ppl
|
3
3
|
|
4
|
-
Version = "1.
|
4
|
+
Version = "1.15.0"
|
5
5
|
|
6
6
|
module Adapter
|
7
7
|
end
|
@@ -24,6 +24,8 @@ module Ppl
|
|
24
24
|
end
|
25
25
|
|
26
26
|
|
27
|
+
require "ppl/adapter/color"
|
28
|
+
require "ppl/adapter/color/colored"
|
27
29
|
require "ppl/adapter/storage"
|
28
30
|
require "ppl/adapter/storage/disk"
|
29
31
|
require "ppl/adapter/storage/factory"
|
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.
|
6
|
-
spec.date = "2013-
|
5
|
+
spec.version = "1.15.0"
|
6
|
+
spec.date = "2013-03-16"
|
7
7
|
|
8
8
|
spec.required_ruby_version = ">= 1.9.3"
|
9
9
|
|
@@ -11,7 +11,9 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.description = "CLI Address Book"
|
12
12
|
spec.license = "GPL-2"
|
13
13
|
|
14
|
+
spec.add_dependency("colored", "1.2")
|
14
15
|
spec.add_dependency("inifile", "2.0.2")
|
16
|
+
spec.add_dependency("morphine", "0.1.1")
|
15
17
|
spec.add_dependency("rugged", "0.17.0.b6")
|
16
18
|
spec.add_dependency("vpim", "0.695")
|
17
19
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
describe Ppl::Adapter::Color::Colored do
|
3
|
+
|
4
|
+
before(:each) do
|
5
|
+
@adapter = Ppl::Adapter::Color::Colored.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#colorize" do
|
9
|
+
|
10
|
+
it "should colorize the string using the monkeypatched String method" do
|
11
|
+
string = "example"
|
12
|
+
string.should_receive(:red).and_return("red example")
|
13
|
+
@adapter.colorize(string, "red").should eq "red example"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should only attempt to colorize the string if the color exists" do
|
17
|
+
string = "example"
|
18
|
+
@adapter.colorize(string, "neon").should eq "example"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
describe Ppl::Adapter::Color do
|
3
|
+
|
4
|
+
before(:each) do
|
5
|
+
@adapter = Ppl::Adapter::Color.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#colorize" do
|
9
|
+
it "should raise not implemented error" do
|
10
|
+
expect{@adapter.colorize(nil, nil)}.to raise_error(NotImplementedError)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|