ppl 1.11.0 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ppl.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Ppl
3
3
 
4
- Version = "1.11.0"
4
+ Version = "1.12.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/age"
43
44
  require "ppl/command/attribute"
44
45
  require "ppl/command/init"
45
46
  require "ppl/command/bday"
@@ -68,6 +69,7 @@ require "ppl/error/contact_not_found"
68
69
  require "ppl/error/incorrect_usage"
69
70
 
70
71
  require "ppl/format/address_book"
72
+ require "ppl/format/address_book/ages"
71
73
  require "ppl/format/address_book/birthdays"
72
74
  require "ppl/format/address_book/email_addresses"
73
75
  require "ppl/format/address_book/mutt_query"
@@ -79,6 +81,7 @@ require "ppl/format/address_book/phone_numbers"
79
81
  require "ppl/format/address_book/postal_addresses"
80
82
  require "ppl/format/address_book/urls"
81
83
  require "ppl/format/contact"
84
+ require "ppl/format/contact/age"
82
85
  require "ppl/format/contact/birthday"
83
86
  require "ppl/format/contact/email_addresses"
84
87
  require "ppl/format/contact/full"
@@ -21,6 +21,7 @@ class Ppl::Application::Bootstrap
21
21
  Ppl::Command::Shell.new,
22
22
  Ppl::Command::Url.new,
23
23
  Ppl::Command::Version.new,
24
+ Ppl::Command::Age.new,
24
25
  ]
25
26
  commands.each do |command|
26
27
  command.storage = storage_adapter
@@ -0,0 +1,50 @@
1
+
2
+ class Ppl::Command::Age < Ppl::Application::Command
3
+
4
+ name "age"
5
+ description "List or show contacts's ages"
6
+
7
+ attr_writer :list_format
8
+ attr_writer :show_format
9
+
10
+ def initialize
11
+ @list_format = Ppl::Format::AddressBook::Ages.new
12
+ @show_format = Ppl::Format::Contact::Age.new
13
+ end
14
+
15
+ def options(parser, options)
16
+ parser.banner = "usage: ppl age"
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_ages
30
+ else
31
+ :show_age
32
+ end
33
+ end
34
+
35
+ def list_ages(input, output)
36
+ address_book = @storage.load_address_book
37
+ formatted = @list_format.process(address_book)
38
+ output.line(formatted)
39
+ return true
40
+ end
41
+
42
+ def show_age(input, output)
43
+ contact = @storage.require_contact(input.arguments.first)
44
+ formatted = @show_format.process(contact)
45
+ output.line(formatted)
46
+ return true
47
+ end
48
+
49
+ end
50
+
@@ -30,5 +30,14 @@ class Ppl::Entity::Contact
30
30
  @email_addresses.include? email_address
31
31
  end
32
32
 
33
+ def age(on_date)
34
+ if @birthday.nil?
35
+ nil
36
+ else
37
+ # From http://stackoverflow.com/a/2357790
38
+ on_date.year - @birthday.year - ((on_date.month > @birthday.month || (on_date.month == @birthday.month && on_date.day >= @birthday.day)) ? 0 : 1)
39
+ end
40
+ end
41
+
33
42
  end
34
43
 
@@ -0,0 +1,29 @@
1
+
2
+ class Ppl::Format::AddressBook::Ages < Ppl::Format::AddressBook
3
+
4
+ attr_writer :table
5
+ attr_writer :date
6
+
7
+ def initialize
8
+ @table = Ppl::Format::Table.new([:id, :age])
9
+ @date = Date.today
10
+ end
11
+
12
+ def process(address_book)
13
+ address_book.contacts.each { |contact| add_row(contact) }
14
+ @table.to_s
15
+ end
16
+
17
+
18
+ private
19
+
20
+ def add_row(contact)
21
+ @table.add_row({
22
+ :id => sprintf("%s:", contact.id),
23
+ :age => contact.age(@date).to_s,
24
+ })
25
+ end
26
+
27
+
28
+ end
29
+
@@ -0,0 +1,9 @@
1
+
2
+ class Ppl::Format::Contact::Age < Ppl::Format::Contact
3
+
4
+ def process(contact)
5
+ contact.age(Date.today).to_s
6
+ end
7
+
8
+ end
9
+
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.11.0"
6
- spec.date = "2013-01-20"
5
+ spec.version = "1.12.0"
6
+ spec.date = "2013-02-16"
7
7
 
8
8
  spec.required_ruby_version = ">= 1.9.3"
9
9
 
@@ -36,6 +36,9 @@ describe Ppl::Application::Bootstrap do
36
36
  it "should contain the 'add' command" do
37
37
  @bootstrap.command_suite.find_command("add").should_not be nil
38
38
  end
39
+ it "should contain the 'age' command" do
40
+ @bootstrap.command_suite.find_command("age").should_not be nil
41
+ end
39
42
  it "should contain the 'bday' command" do
40
43
  @bootstrap.command_suite.find_command("bday").should_not be nil
41
44
  end
@@ -0,0 +1,43 @@
1
+
2
+ describe Ppl::Command::Age do
3
+
4
+ before(:each) do
5
+ @command = Ppl::Command::Age.new
6
+ @input = Ppl::Application::Input.new
7
+ @output = double(Ppl::Application::Output)
8
+ @storage = double(Ppl::Adapter::Storage)
9
+ @list_format = double(Ppl::Format::AddressBook)
10
+ @show_format = double(Ppl::Format::Contact)
11
+
12
+ @command.list_format = @list_format
13
+ @command.show_format = @show_format
14
+ @command.storage = @storage
15
+ end
16
+
17
+ describe "#name" do
18
+ it "should be 'age'" do
19
+ @command.name.should eq "age"
20
+ end
21
+ end
22
+
23
+ describe "#execute" do
24
+
25
+ it "should list contacts' ages if no arguments are given" do
26
+ @storage.should_receive(:load_address_book)
27
+ @list_format.should_receive(:process)
28
+ @output.should_receive(:line)
29
+ @command.execute(@input, @output)
30
+ end
31
+
32
+ it "should show a single contact's ages if one is specified" do
33
+ @input.arguments = ["jdoe"]
34
+ @storage.should_receive(:require_contact)
35
+ @show_format.should_receive(:process)
36
+ @output.should_receive(:line)
37
+ @command.execute(@input, @output)
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+
@@ -70,5 +70,15 @@ describe Ppl::Entity::Contact do
70
70
  end
71
71
  end
72
72
 
73
+ describe "#age" do
74
+ it "should return nil if the date of birth is unknown" do
75
+ @contact.age(Date.today).should eq nil
76
+ end
77
+ it "should return the contact's age" do
78
+ @contact.birthday = Date.parse("1970-01-01")
79
+ @contact.age(Date.parse("1980-01-02")).should eq 10
80
+ end
81
+ end
82
+
73
83
  end
74
84
 
@@ -0,0 +1,37 @@
1
+
2
+ describe Ppl::Format::AddressBook::Ages do
3
+
4
+ before(:each) do
5
+ @format = Ppl::Format::AddressBook::Ages.new
6
+ @address_book = Ppl::Entity::AddressBook.new
7
+ @contact = Ppl::Entity::Contact.new
8
+ @table = double(Ppl::Format::Table)
9
+ @contact.id = "test"
10
+ @format.table = @table
11
+ @format.date = Date.parse("1980-01-02")
12
+ @address_book.contacts.push(@contact)
13
+ end
14
+
15
+ describe "#process" do
16
+
17
+ it "should at least show the contact's id" do
18
+ @table.should_receive(:add_row).with({
19
+ :id => "test:",
20
+ :age => "",
21
+ })
22
+ @format.process(@address_book)
23
+ end
24
+
25
+ it "should show an age if it's available" do
26
+ @contact.birthday = Date.parse("1970-01-01")
27
+ @table.should_receive(:add_row).with({
28
+ :id => "test:",
29
+ :age => "10",
30
+ })
31
+ @format.process(@address_book)
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+
@@ -0,0 +1,24 @@
1
+
2
+ describe Ppl::Format::Contact::Age do
3
+
4
+ before(:each) do
5
+ @format = Ppl::Format::Contact::Age.new
6
+ @contact = double(Ppl::Entity::Contact)
7
+ end
8
+
9
+ describe "#process" do
10
+
11
+ it "should return an empty string if the contact lacks a birth date" do
12
+ @contact.should_receive(:age).and_return(nil)
13
+ @format.process(@contact).should eq ""
14
+ end
15
+
16
+ it "should return the contact's age if the birthdate is known" do
17
+ @contact.should_receive(:age).and_return(10)
18
+ @format.process(@contact).should eq "10"
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
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.11.0
4
+ version: 1.12.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,41 +9,56 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-20 00:00:00.000000000 Z
12
+ date: 2013-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: inifile
16
- requirement: &12830980 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - =
19
+ - - '='
20
20
  - !ruby/object:Gem::Version
21
21
  version: 2.0.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *12830980
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.2
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rugged
27
- requirement: &12830520 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
- - - =
35
+ - - '='
31
36
  - !ruby/object:Gem::Version
32
37
  version: 0.17.0.b6
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *12830520
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.17.0.b6
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: vpim
38
- requirement: &12830060 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
- - - =
51
+ - - '='
42
52
  - !ruby/object:Gem::Version
43
53
  version: '0.695'
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *12830060
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: '0.695'
47
62
  description: CLI Address Book
48
63
  email: henry@henrysmith.org
49
64
  executables:
@@ -75,6 +90,7 @@ files:
75
90
  - lib/ppl/application/router.rb
76
91
  - lib/ppl/application/shell.rb
77
92
  - lib/ppl/command/add.rb
93
+ - lib/ppl/command/age.rb
78
94
  - lib/ppl/command/attribute.rb
79
95
  - lib/ppl/command/bday.rb
80
96
  - lib/ppl/command/email.rb
@@ -99,6 +115,7 @@ files:
99
115
  - lib/ppl/error/contact_not_found.rb
100
116
  - lib/ppl/error/incorrect_usage.rb
101
117
  - lib/ppl/format/address_book.rb
118
+ - lib/ppl/format/address_book/ages.rb
102
119
  - lib/ppl/format/address_book/birthdays.rb
103
120
  - lib/ppl/format/address_book/email_addresses.rb
104
121
  - lib/ppl/format/address_book/mutt_query.rb
@@ -110,6 +127,7 @@ files:
110
127
  - lib/ppl/format/address_book/postal_addresses.rb
111
128
  - lib/ppl/format/address_book/urls.rb
112
129
  - lib/ppl/format/contact.rb
130
+ - lib/ppl/format/contact/age.rb
113
131
  - lib/ppl/format/contact/birthday.rb
114
132
  - lib/ppl/format/contact/email_addresses.rb
115
133
  - lib/ppl/format/contact/full.rb
@@ -138,6 +156,7 @@ files:
138
156
  - spec/ppl/application/router_spec.rb
139
157
  - spec/ppl/application/shell_spec.rb
140
158
  - spec/ppl/command/add_spec.rb
159
+ - spec/ppl/command/age_spec.rb
141
160
  - spec/ppl/command/attribute_spec.rb
142
161
  - spec/ppl/command/bday_spec.rb
143
162
  - spec/ppl/command/email_spec.rb
@@ -159,6 +178,7 @@ files:
159
178
  - spec/ppl/entity/address_book_spec.rb
160
179
  - spec/ppl/entity/contact_spec.rb
161
180
  - spec/ppl/entity/postal_address_spec.rb
181
+ - spec/ppl/format/address_book/ages_spec.rb
162
182
  - spec/ppl/format/address_book/birthdays_spec.rb
163
183
  - spec/ppl/format/address_book/email_addresses_spec.rb
164
184
  - spec/ppl/format/address_book/mutt_query_spec.rb
@@ -170,6 +190,7 @@ files:
170
190
  - spec/ppl/format/address_book/postal_addresses_spec.rb
171
191
  - spec/ppl/format/address_book/urls_spec.rb
172
192
  - spec/ppl/format/address_book_spec.rb
193
+ - spec/ppl/format/contact/age_spec.rb
173
194
  - spec/ppl/format/contact/birthday_spec.rb
174
195
  - spec/ppl/format/contact/email_addresses_spec.rb
175
196
  - spec/ppl/format/contact/full_spec.rb
@@ -205,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
226
  version: '0'
206
227
  requirements: []
207
228
  rubyforge_project:
208
- rubygems_version: 1.8.11
229
+ rubygems_version: 1.8.23
209
230
  signing_key:
210
231
  specification_version: 3
211
232
  summary: CLI Address Book