ppl 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,6 +13,7 @@ ppl if:
13
13
  * You prefer to keep your data stored in an open format
14
14
 
15
15
  [![Build Status](https://secure.travis-ci.org/h2s/ppl.png)](http://travis-ci.org/h2s/ppl)
16
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/h2s/ppl)
16
17
 
17
18
  Installation
18
19
  ------------
data/lib/ppl.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Ppl
3
3
 
4
- Version = "1.5.0"
4
+ Version = "1.5.1"
5
5
 
6
6
  module Adapter
7
7
  end
@@ -5,72 +5,111 @@ class Ppl::Adapter::Vcard::Vpim
5
5
 
6
6
  def encode(contact)
7
7
  vcard = Vpim::Vcard::Maker.make2 do |maker|
8
+ encode_birthday(contact, maker)
9
+ encode_name(contact, maker)
10
+ encode_email_addresses(contact, maker)
11
+ encode_phone_number(contact, maker)
12
+ encode_organization(contact, maker)
13
+ encode_postal_address(contact, maker)
14
+ encode_email_addresses(contact, maker)
15
+ end
16
+ vcard.to_s
17
+ end
8
18
 
9
- if !contact.birthday.nil?
10
- maker.birthday = contact.birthday
11
- end
19
+ def decode(string)
20
+ vcard = Vpim::Vcard.decode(string).first
21
+ contact = Ppl::Entity::Contact.new
22
+ decode_birthday(vcard, contact)
23
+ decode_email_addresses(vcard, contact)
24
+ decode_phone_number(vcard, contact)
25
+ decode_postal_address(vcard, contact)
26
+ decode_organization(vcard, contact)
27
+ decode_name(vcard, contact)
28
+ return contact
29
+ end
12
30
 
13
- maker.add_name do |name|
14
- name.given = contact.id unless contact.id.nil?
15
- name.fullname = contact.name unless contact.name.nil?
16
- end
17
31
 
18
- contact.email_addresses.each do |email_address|
19
- maker.add_email(email_address)
20
- end
32
+ private
21
33
 
22
- if !contact.phone_number.nil?
23
- maker.add_tel(contact.phone_number)
24
- end
34
+ def encode_birthday(contact, vcard_maker)
35
+ if !contact.birthday.nil?
36
+ vcard_maker.birthday = contact.birthday
37
+ end
38
+ end
25
39
 
26
- if !contact.organization.nil?
27
- maker.org=(contact.organization)
28
- end
40
+ def encode_name(contact, vcard_maker)
41
+ vcard_maker.add_name do |name|
42
+ name.given = contact.id unless contact.id.nil?
43
+ name.fullname = contact.name unless contact.name.nil?
44
+ end
45
+ end
46
+
47
+ def encode_email_addresses(contact, vcard_maker)
48
+ contact.email_addresses.each do |email_address|
49
+ vcard_maker.add_email(email_address)
50
+ end
51
+ end
52
+
53
+ def encode_phone_number(contact, vcard_maker)
54
+ if !contact.phone_number.nil?
55
+ vcard_maker.add_tel(contact.phone_number)
56
+ end
57
+ end
58
+
59
+ def encode_organization(contact, vcard_maker)
60
+ if !contact.organization.nil?
61
+ vcard_maker.org=(contact.organization)
62
+ end
63
+ end
29
64
 
30
- if !contact.postal_address.nil?
31
- maker.add_addr do |address|
32
- if !contact.postal_address.street.nil?
33
- address.street = contact.postal_address.street
34
- end
35
- if !contact.postal_address.postal_code.nil?
36
- address.postalcode = contact.postal_address.postal_code
37
- end
38
- if !contact.postal_address.po_box.nil?
39
- address.pobox = contact.postal_address.po_box
40
- end
41
- if !contact.postal_address.country.nil?
42
- address.country = contact.postal_address.country
43
- end
44
- if !contact.postal_address.region.nil?
45
- address.region = contact.postal_address.region
46
- end
47
- if !contact.postal_address.locality.nil?
48
- address.locality = contact.postal_address.locality
49
- end
65
+ def encode_postal_address(contact, vcard_maker)
66
+ if !contact.postal_address.nil?
67
+ vcard_maker.add_addr do |address|
68
+ if !contact.postal_address.street.nil?
69
+ address.street = contact.postal_address.street
70
+ end
71
+ if !contact.postal_address.postal_code.nil?
72
+ address.postalcode = contact.postal_address.postal_code
73
+ end
74
+ if !contact.postal_address.po_box.nil?
75
+ address.pobox = contact.postal_address.po_box
76
+ end
77
+ if !contact.postal_address.country.nil?
78
+ address.country = contact.postal_address.country
79
+ end
80
+ if !contact.postal_address.region.nil?
81
+ address.region = contact.postal_address.region
82
+ end
83
+ if !contact.postal_address.locality.nil?
84
+ address.locality = contact.postal_address.locality
50
85
  end
51
86
  end
52
-
53
87
  end
88
+ end
54
89
 
55
- return vcard.to_s
90
+ def decode_birthday(vcard, contact)
91
+ contact.birthday = vcard.birthday unless vcard.birthday.nil?
56
92
  end
57
93
 
58
- def decode(string)
59
- vcard = Vpim::Vcard.decode(string).first
60
- contact = Ppl::Entity::Contact.new
94
+ def decode_name(vcard, contact)
95
+ if !vcard.name.nil?
96
+ contact.name = vcard.name.fullname
97
+ end
98
+ end
61
99
 
62
- if !vcard.birthday.nil?
63
- contact.birthday = vcard.birthday
100
+ def decode_organization(vcard, contact)
101
+ if !vcard.org.nil?
102
+ contact.organization = vcard.org.first
64
103
  end
104
+ end
65
105
 
106
+ def decode_email_addresses(vcard, contact)
66
107
  vcard.emails.each do |email|
67
108
  contact.email_addresses.push(email.to_s)
68
109
  end
110
+ end
69
111
 
70
- if !vcard.telephones.empty?
71
- contact.phone_number = vcard.telephones.first
72
- end
73
-
112
+ def decode_postal_address(vcard, contact)
74
113
  if !vcard.address.nil?
75
114
  contact.postal_address = Ppl::Entity::PostalAddress.new
76
115
  contact.postal_address.street = vcard.address.street
@@ -80,19 +119,12 @@ class Ppl::Adapter::Vcard::Vpim
80
119
  contact.postal_address.region = vcard.address.region
81
120
  contact.postal_address.country = vcard.address.country
82
121
  end
122
+ end
83
123
 
84
- if !vcard.org.nil?
85
- contact.organization = vcard.org.first
86
- end
87
-
88
- name = nil
89
- name = vcard.name
90
-
91
- if !name.nil?
92
- contact.name = name.fullname
124
+ def decode_phone_number(vcard, contact)
125
+ if !vcard.telephones.empty?
126
+ contact.phone_number = vcard.telephones.first
93
127
  end
94
-
95
- return contact
96
128
  end
97
129
 
98
130
  end
@@ -72,14 +72,14 @@ class Ppl::Command::Post < Ppl::Application::Command
72
72
 
73
73
  def set_postal_address(input, output)
74
74
  contact = @storage.require_contact(input.arguments[0])
75
- contact.set_postal_address do |address|
76
- address.country = input.options[:country] unless input.options[:country].nil?
77
- address.locality = input.options[:locality] unless input.options[:locality].nil?
78
- address.region = input.options[:region] unless input.options[:region].nil?
79
- address.po_box = input.options[:po_box] unless input.options[:po_box].nil?
80
- address.postal_code = input.options[:postal_code] unless input.options[:postal_code].nil?
81
- address.street = input.options[:street] unless input.options[:street].nil?
75
+
76
+ [:country, :locality, :region, :po_box, :postal_code, :street].each do |property|
77
+ next if input.options[property].nil?
78
+ contact.set_postal_address do |address|
79
+ address.send("#{property.to_s}=", input.options[property])
80
+ end
82
81
  end
82
+
83
83
  @storage.save_contact(contact)
84
84
  end
85
85
 
@@ -16,27 +16,27 @@ class Ppl::Format::AddressBook::PostalAddresses < Ppl::Format::AddressBook
16
16
  private
17
17
 
18
18
  def add_row(contact)
19
- id = sprintf("%s:", contact.id)
20
19
  postal_address = nil
21
-
22
20
  if !contact.postal_address.nil?
23
- pieces = [
24
- contact.postal_address.street,
25
- contact.postal_address.locality,
26
- contact.postal_address.region,
27
- contact.postal_address.country,
28
- contact.postal_address.postal_code,
29
- contact.postal_address.po_box,
30
- ].select { |property| property != "" && !property.nil? }
31
- postal_address = pieces.join(", ")
21
+ postal_address = format_postal_address(contact.postal_address)
32
22
  end
33
-
34
23
  @table.add_row({
35
- :id => id,
24
+ :id => sprintf("%s:", contact.id),
36
25
  :postal_address => postal_address,
37
26
  })
38
27
  end
39
28
 
29
+ def format_postal_address(postal_address)
30
+ pieces = [
31
+ postal_address.street,
32
+ postal_address.locality,
33
+ postal_address.region,
34
+ postal_address.country,
35
+ postal_address.postal_code,
36
+ postal_address.po_box,
37
+ ].select { |property| property != "" && !property.nil? }
38
+ pieces.join(", ")
39
+ end
40
40
 
41
41
  end
42
42
 
@@ -10,20 +10,22 @@ class Ppl::Format::Contact::PostalAddress < Ppl::Format::Contact
10
10
  def process(contact)
11
11
  address = contact.postal_address
12
12
 
13
- {
14
- :street => "Street",
15
- :postal_code => "Postal Code",
16
- :po_box => "PO box",
17
- :locality => "Locality",
18
- :region => "Region",
19
- :country => "Country",
20
- }.each do |property, name|
21
- value = address.send(property)
22
- next if value.nil? || value == ""
23
- @table.add_row({
24
- :label => sprintf("%s:", name),
25
- :value => address.send(property)
26
- })
13
+ if !address.nil?
14
+ {
15
+ :street => "Street",
16
+ :postal_code => "Postal Code",
17
+ :po_box => "PO box",
18
+ :locality => "Locality",
19
+ :region => "Region",
20
+ :country => "Country",
21
+ }.each do |property, name|
22
+ value = address.send(property)
23
+ next if value.nil? || value == ""
24
+ @table.add_row({
25
+ :label => sprintf("%s:", name),
26
+ :value => address.send(property)
27
+ })
28
+ end
27
29
  end
28
30
 
29
31
  return @table.to_s
data/ppl.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |spec|
3
3
 
4
4
  spec.name = "ppl"
5
- spec.version = "1.5.0"
5
+ spec.version = "1.5.1"
6
6
  spec.date = "2012-12-20"
7
7
 
8
8
  spec.required_ruby_version = ">= 1.9.3"
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.5.0
4
+ version: 1.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: inifile
16
- requirement: &5576920 !ruby/object:Gem::Requirement
16
+ requirement: &14299780 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.0.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *5576920
24
+ version_requirements: *14299780
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rugged
27
- requirement: &5576360 !ruby/object:Gem::Requirement
27
+ requirement: &14298340 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - =
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.17.0.b6
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *5576360
35
+ version_requirements: *14298340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: vpim
38
- requirement: &5563160 !ruby/object:Gem::Requirement
38
+ requirement: &14297560 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - =
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0.695'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *5563160
46
+ version_requirements: *14297560
47
47
  description: CLI Address Book
48
48
  email: henry@henrysmith.org
49
49
  executables: