ppl 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
 
2
+ gem 'active_support'
3
+
2
4
  gem "colored", "~> 1.2"
3
5
 
4
6
  gem "vpim", "12.1.12", :git => "git://github.com/sam-github/vpim.git"
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  _____ _____ __
2
2
  | _ || _ || |
3
- | __|| __|| |
3
+ | __|| __|| |__
4
4
  |__| |__| |_____|
5
5
 
6
6
 
@@ -11,23 +11,70 @@ like "people". You might be interested in ppl if:
11
11
  * You want ownership of your address book data back from the cloud
12
12
  * You prefer to keep your data stored in an open format
13
13
 
14
- The Plan
15
- --------
16
14
 
17
- ppl's command-line interface is based on those of Git and Heroku. For example:
15
+ Usage
16
+ -----
18
17
 
18
+ ### List all contacts
19
19
 
20
- $ ppl list
21
- fred Fred Smith fred.smith@example.org
22
- dave Dave Jones dave.jones@example.org
23
- joe Joe Bloggs joe.bloggs@example.org
20
+ ```bash
21
+ $ ppl list
22
+ fred Fred Smith fred.smith@example.org
23
+ dave Dave Jones dave.jones@example.org
24
+ joe Joe Bloggs joe.bloggs@example.org
25
+ ```
24
26
 
25
- Or...
27
+ ### Show a single contact
26
28
 
27
- $ ppl show fred
28
- Fred Smith
29
- fred.simth@example.org
29
+ ```bash
30
+ $ ppl show fred
31
+ Fred Smith
32
+ fred.simth@example.org
30
33
 
31
- Birthday 1980-01-01
32
- Cellphone 01189998819991197253
34
+ Birthday 1980-01-01
35
+ Cellphone 01189998819991197253
36
+ ````
33
37
 
38
+ ### List upcoming birthdays
39
+
40
+ ```bash
41
+ $ ppl birthdays
42
+ fred Fred Smith 1980-01-01 99 days
43
+ dave Dave Jones 1980-01-02 100 days
44
+ joe Joe Bloggs 1980-01-03 101 days
45
+ ```
46
+
47
+ Roadmap
48
+ -------
49
+
50
+ Support for the following commands is planned.
51
+
52
+ ### Add a contact
53
+ ```bash
54
+ $ ppl add adam --email=adam.brown@example.org --birthday=1980-01-04
55
+ ```
56
+
57
+ ### Update a contact
58
+ ```bash
59
+ $ ppl set adam --email=adam.brown@example.com
60
+ ```
61
+
62
+ ### Rename a contact
63
+ ```bash
64
+ $ ppl mv adam workadam
65
+ ```
66
+
67
+ ### Delete a contact
68
+ ```bash
69
+ $ ppl rm workadam
70
+ ```
71
+
72
+ In a highly optimistic version of the future, I plan to integrate Git.
73
+ Any commands that modify the address book will also commit their changes.
74
+ Then this will be posisble:
75
+ ```bash
76
+ $ ppl sync
77
+ Pulling latest changes from all remotes...
78
+ Pushing local changes to all remotes...
79
+ Done
80
+ ```
@@ -0,0 +1,42 @@
1
+
2
+ require "vpim/vcard"
3
+ require "enumerator"
4
+
5
+ class Ppl::Address_Book
6
+
7
+ include Enumerable
8
+
9
+ def initialize(path)
10
+ @path = path
11
+ end
12
+
13
+ def contact(id)
14
+ filename = File.join @path, id + ".vcard"
15
+ vcard = IO.read filename
16
+ vcard = Vpim::Vcard.decode(vcard).first
17
+ contact = Ppl::Contact.new(id, vcard)
18
+ end
19
+
20
+ def contacts
21
+ pattern = File.join @path, "*.vcard"
22
+ filenames = Dir.glob pattern
23
+ contacts = []
24
+
25
+ filenames.each do |filename|
26
+ id = File.basename(filename).slice(0..-7)
27
+ contacts.push self.contact(id);
28
+ end
29
+ contacts
30
+
31
+ end
32
+
33
+ def each
34
+ self.contacts.each { |c| yield c }
35
+ end
36
+
37
+ def with_birthday
38
+ self.find_all { |contact| contact.birthday.nil? == false }
39
+ end
40
+
41
+ end
42
+
data/lib/ppl/cli.rb CHANGED
@@ -5,7 +5,13 @@ require "ppl/command"
5
5
  class Ppl::CLI
6
6
 
7
7
  def self.start(*args)
8
- command = args.shift.strip
8
+
9
+ command = args.shift
10
+ if command
11
+ command = command.strip
12
+ else
13
+ command = "help"
14
+ end
9
15
 
10
16
  Ppl::Command.load
11
17
  Ppl::Command.run(command, args)
@@ -1,4 +1,8 @@
1
1
 
2
+ require "vpim/vcard"
3
+ require "colored"
4
+
5
+
2
6
  class Ppl::Command::Base
3
7
 
4
8
 
@@ -9,8 +13,17 @@ class Ppl::Command::Base
9
13
  def initialize(arguments=[], options={})
10
14
  @arguments = arguments
11
15
  @options = options
16
+
17
+ @address_book = Ppl::Address_Book.new(@options[:path])
18
+ end
19
+
20
+
21
+ def name
12
22
  end
13
23
 
14
24
 
25
+ def summary
26
+ end
27
+
15
28
  end
16
29
 
@@ -0,0 +1,27 @@
1
+
2
+ class Ppl::Command::Birthdays < Ppl::Command::Base
3
+
4
+ def name
5
+ "birthdays"
6
+ end
7
+
8
+ def summary
9
+ "Show a list of upcoming birthdays"
10
+ end
11
+
12
+ def index
13
+ today = Date.today
14
+
15
+ @address_book.with_birthday.each do |contact|
16
+ puts(
17
+ sprintf("%-20s", contact.id) +
18
+ sprintf("%-20s", contact.name) +
19
+ sprintf("%-20s", contact.birthday) +
20
+ sprintf("%d days", contact.until_birthday(today))
21
+ )
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
@@ -0,0 +1,29 @@
1
+
2
+ class Ppl::Command::Help < Ppl::Command::Base
3
+
4
+ def name
5
+ "help"
6
+ end
7
+
8
+ def summary
9
+ "Show a list of available commands"
10
+ end
11
+
12
+ def index
13
+
14
+ puts
15
+ Ppl::Command.constants.each do |constant|
16
+ if constant.to_s != "Base"
17
+ command = Ppl::Command.const_get(constant).new(@arguments, @options)
18
+ puts(
19
+ sprintf(" %-10s", command.name) +
20
+ sprintf("%s", command.summary)
21
+ )
22
+ end
23
+ end
24
+ puts
25
+
26
+ end
27
+
28
+ end
29
+
@@ -1,29 +1,22 @@
1
1
 
2
- require "vpim/vcard"
3
- require "colored"
4
-
5
2
  class Ppl::Command::List < Ppl::Command::Base
6
3
 
7
- def index
8
-
9
- pattern = @options[:path] + "/*.vcard"
10
- contacts = Dir.glob pattern
11
-
12
- contacts.each do |filename|
13
-
14
- id = File.basename(filename).slice(0..-7)
4
+ def name
5
+ "list"
6
+ end
15
7
 
16
- vcard = IO.read filename
17
- vcard = Vpim::Vcard.decode(vcard).first
8
+ def summary
9
+ "Show a list of all contacts"
10
+ end
18
11
 
12
+ def index
13
+ @address_book.each do |contact|
19
14
  puts(
20
- sprintf("%-20s", id).red +
21
- sprintf("%-20s", vcard.name.fullname).yellow +
22
- sprintf("%-20s", vcard.email).blue
15
+ sprintf("%-20s", contact.id).red +
16
+ sprintf("%-20s", contact.name).yellow +
17
+ sprintf("%-20s", contact.email).blue
23
18
  )
24
-
25
19
  end
26
-
27
20
  end
28
21
 
29
22
  end
@@ -0,0 +1,25 @@
1
+
2
+ require "ppl/command/base"
3
+
4
+ class Ppl::Command::Show < Ppl::Command::Base
5
+
6
+ def name
7
+ "show"
8
+ end
9
+
10
+ def summary
11
+ "Show full details of a single contact"
12
+ end
13
+
14
+ def index
15
+ contact = @address_book.contact @arguments.first
16
+
17
+ puts contact.name.yellow
18
+ contact.emails.each do |email|
19
+ puts email.blue
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+
data/lib/ppl/command.rb CHANGED
@@ -14,7 +14,10 @@ module Ppl
14
14
  :path => "/home/h2s/doc/contacts"
15
15
  }
16
16
 
17
+ klass = command.capitalize
18
+
17
19
  command = Ppl::Command::List.new(arguments, options)
20
+ command = Ppl::Command.const_get(klass).new(arguments, options)
18
21
  command.send("index")
19
22
  end
20
23
 
@@ -0,0 +1,38 @@
1
+
2
+ require "active_support/core_ext/time/calculations.rb"
3
+
4
+ class Ppl::Contact
5
+
6
+ attr_reader :id
7
+
8
+ def initialize(id, vcard)
9
+ @id = id
10
+ @vcard = vcard
11
+ end
12
+
13
+ def birthday
14
+ @vcard.birthday
15
+ end
16
+
17
+ def until_birthday(now)
18
+ birthday = self.birthday.dup
19
+ while birthday < now
20
+ birthday = birthday.advance :years => 1
21
+ end
22
+ birthday - now
23
+ end
24
+
25
+ def email
26
+ @vcard.emails.first
27
+ end
28
+
29
+ def emails
30
+ @vcard.emails
31
+ end
32
+
33
+ def name
34
+ @vcard.name.fullname
35
+ end
36
+
37
+ end
38
+
data/lib/ppl.rb CHANGED
@@ -2,3 +2,6 @@
2
2
  module Ppl
3
3
  end
4
4
 
5
+ require "ppl/address_book"
6
+ require "ppl/contact"
7
+
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 = "0.0.2"
6
- spec.date = "2012-11-10"
5
+ spec.version = "0.0.4"
6
+ spec.date = "2012-11-11"
7
7
 
8
8
  spec.summary = "CLI Address Book"
9
9
  spec.description = "Command-line driven address book"
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: 0.0.2
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-10 00:00:00.000000000 Z
12
+ date: 2012-11-11 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Command-line driven address book
15
15
  email: henry@henrysmith.org
@@ -18,17 +18,21 @@ executables:
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
- - COPYING.txt
21
+ - COPYING
22
22
  - Gemfile
23
23
  - Gemfile.lock
24
24
  - README.md
25
25
  - bin/ppl
26
26
  - lib/ppl.rb
27
+ - lib/ppl/address_book.rb
27
28
  - lib/ppl/cli.rb
28
29
  - lib/ppl/command.rb
29
30
  - lib/ppl/command/base.rb
31
+ - lib/ppl/command/birthdays.rb
32
+ - lib/ppl/command/help.rb
30
33
  - lib/ppl/command/list.rb
31
34
  - lib/ppl/command/show.rb
35
+ - lib/ppl/contact.rb
32
36
  - lib/ppl/ppl.rb
33
37
  - ppl.gemspec
34
38
  homepage: https://github.com/h2s/ppl
File without changes