ppl 1.15.1 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7a6a79415d099361118edf8c6d6a55d588a8efb
4
- data.tar.gz: fa7c00ded45c0a0ec2d3f97a161b06e40fec94ee
3
+ metadata.gz: e0078cdc91873e6cbc509e8ab7688372fef43c7b
4
+ data.tar.gz: 4c5005c26f11a26b11a6adf4e99195f358c8f438
5
5
  SHA512:
6
- metadata.gz: f8c037f64e3016665e6f388be1ae411ed2a503a0adfc525bfbda5d6840a0c12e125120b1eb94b930d4a6dddef0035a833ad79a5eab046da7205c797ef895a87c
7
- data.tar.gz: 08b7a136a3f7c60a45da397ddd972c7517259ed41d943e25f5a79c520f3339abb75745e0af2ac3bc0670c4fce5283afd19e20336ce6946db15ccc23ab6a05b17
6
+ metadata.gz: 814ba206fc2673082c196aceaea8cb26d9bbfb47e6b7db8d4784d8fd5c5c63fabfd0bdc0d9727ed5ad25313d1d7a276799f98e5df02ea66607c0719a3bbd5d65
7
+ data.tar.gz: 59952d9c2d48c6395290c922126c06fc958760ffd17fc4911a869dbc8d12829af7ca169a8edf1f7bde3b4e2d4daeadbcf8a1d60847986d60cb7ac618f7f9c4ef
@@ -8,9 +8,13 @@ class Ppl::Command::Mutt < Ppl::Application::Command
8
8
 
9
9
  def options(parser, options)
10
10
  parser.banner = "usage: ppl mutt <query>"
11
+ parser.on("-i", "--ignore-case", "Turn off case sensitivity") do |i|
12
+ options[:ignore_case] = i
13
+ end
11
14
  end
12
15
 
13
16
  def execute(input, output)
17
+ @options = input.options
14
18
  query = require_query(input)
15
19
  matches = mutt_search(query)
16
20
  output.line(describe_result(matches))
@@ -29,23 +33,43 @@ class Ppl::Command::Mutt < Ppl::Application::Command
29
33
 
30
34
  def mutt_search(query)
31
35
  @address_book = @storage.load_address_book
36
+ select_matching_contacts(@address_book, query)
37
+ end
38
+
39
+ def select_matching_contacts(address_book, query)
32
40
  matches = Ppl::Entity::AddressBook.new
41
+ address_book.contacts.each do |contact|
42
+ if contact.email_addresses.empty?
43
+ next
44
+ elsif match_by_name(contact, query)
45
+ matches.contacts << contact
46
+ elsif match_by_email_address(contact, query)
47
+ matches.contacts << contact
48
+ end
49
+ end
50
+ matches
51
+ end
33
52
 
34
- @address_book.contacts.each do |contact|
35
- next if contact.email_addresses.empty?
53
+ def match_by_name(contact, query)
54
+ if @options[:ignore_case]
55
+ contact.name.downcase.include? query.downcase
56
+ else
57
+ contact.name.include? query
58
+ end
59
+ end
36
60
 
37
- matching_emails = contact.email_addresses.select do |email_address|
61
+ def match_by_email_address(contact, query)
62
+ matches = contact.email_addresses.select do |email_address|
63
+ if @options[:ignore_case]
64
+ email_address.downcase.include? query.downcase
65
+ else
38
66
  email_address.include? query
39
67
  end
40
-
41
- if matching_emails.length > 0
42
- matches.contacts.push(contact)
43
- elsif !contact.name.nil? && contact.name.include?(query)
44
- matches.contacts.push(contact)
45
- end
46
68
  end
47
-
48
- matches
69
+ if matches.length > 0
70
+ contact.email_addresses = matches
71
+ true
72
+ end
49
73
  end
50
74
 
51
75
  def describe_result(matches)
@@ -9,25 +9,24 @@ class Ppl::Format::AddressBook::MuttQuery < Ppl::Format::AddressBook
9
9
  end
10
10
 
11
11
  def process(address_book)
12
- address_book.contacts.each { |contact| add_row(contact) }
12
+ address_book.contacts.each { |contact| add_contact(contact) }
13
13
  @table.to_s
14
14
  end
15
15
 
16
-
17
16
  private
18
17
 
19
- def add_row(contact)
20
- name = nil
21
- if !contact.name.nil?
22
- name = contact.name
18
+ def add_contact(contact)
19
+ contact.email_addresses.each do |email_address|
20
+ add_email_address(email_address, contact.name)
23
21
  end
22
+ end
24
23
 
24
+ def add_email_address(email_address, name)
25
25
  @table.add_row({
26
- :email => contact.email_addresses.first,
26
+ :email => email_address,
27
27
  :name => name,
28
28
  })
29
29
  end
30
30
 
31
-
32
31
  end
33
32
 
data/lib/ppl.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Ppl
3
3
 
4
- Version = "1.15.1"
4
+ Version = "1.16.0"
5
5
 
6
6
  module Adapter
7
7
  end
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.15.1"
6
- spec.date = "2013-04-11"
5
+ spec.version = "1.16.0"
6
+ spec.date = "2013-04-12"
7
7
 
8
8
  spec.required_ruby_version = ">= 1.9.3"
9
9
 
@@ -51,6 +51,22 @@ describe Ppl::Command::Mutt do
51
51
  @command.execute(@input, @output).should eq true
52
52
  end
53
53
 
54
+ it "should only return matching email addresses" do
55
+ @input.arguments.push "prova"
56
+ @contact.name = "Test User"
57
+
58
+ @contact.email_addresses.push "test@test.org"
59
+ @contact.email_addresses.push "prova@prova.org"
60
+ @address_book.contacts.push(@contact)
61
+ @storage.stub(:load_address_book).and_return(@address_book)
62
+ @format.should_receive(:process) do |address_book|
63
+ address_book.contacts[0].email_addresses.length.should eq 1
64
+ address_book.contacts[0].email_addresses[0].should eq "prova@prova.org"
65
+ end
66
+ @output.stub(:line)
67
+ @command.execute(@input, @output)
68
+ end
69
+
54
70
  it "should return name matches" do
55
71
 
56
72
  @contact.name = "Test User"
@@ -68,6 +84,36 @@ describe Ppl::Command::Mutt do
68
84
  @command.execute(@input, @output).should eq true
69
85
  end
70
86
 
87
+ end
88
+
89
+ describe "#execute (case-insensitive)" do
90
+
91
+ before(:each) do
92
+ @input.options[:ignore_case] = true
93
+ @contact.name = "Joe Schmoe"
94
+ @contact.email_addresses.push "joe@somewhere.com"
95
+ @contact.email_addresses.push "LOUD@SHOUTING.COM"
96
+ @address_book.contacts << @contact
97
+ @storage.stub(:load_address_book).and_return(@address_book)
98
+ @output.stub(:line)
99
+ end
100
+
101
+ it "should ignore case when matching names" do
102
+ @input.arguments.push "joe schmoe"
103
+ @format.should_receive(:process) do |address_book|
104
+ address_book.contacts[0].email_addresses.length.should eq 2
105
+ end
106
+ @command.execute(@input, @output)
107
+ end
108
+
109
+ it "should ignore case when matching email addresses" do
110
+ @input.arguments.push "loud"
111
+ @format.should_receive(:process) do |address_book|
112
+ address_book.contacts[0].email_addresses.length.should eq 1
113
+ address_book.contacts[0].email_addresses[0].should eq "LOUD@SHOUTING.COM"
114
+ end
115
+ @command.execute(@input, @output)
116
+ end
71
117
 
72
118
  end
73
119
 
@@ -24,6 +24,19 @@ describe Ppl::Format::AddressBook::MuttQuery do
24
24
  @format.process(@address_book)
25
25
  end
26
26
 
27
+ it "should list all of each contact's email addresses" do
28
+ @contact.email_addresses.push "test2@example.com"
29
+ @table.should_receive(:add_row).with({
30
+ :email => "test@example.org",
31
+ :name => "Test Contact",
32
+ })
33
+ @table.should_receive(:add_row).with({
34
+ :email => "test2@example.com",
35
+ :name => "Test Contact",
36
+ })
37
+ @format.process(@address_book)
38
+ end
39
+
27
40
  end
28
41
 
29
42
  end
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.15.1
4
+ version: 1.16.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 00:00:00.000000000 Z
11
+ date: 2013-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored