friends 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 625e3744b0240347b4e0c74a3a4063b672afab88
4
- data.tar.gz: 25d066d3bb99d407adb41f01785772f514e7d4fa
3
+ metadata.gz: 018ee9e9043561fd60353d6db09a37ca42822a8d
4
+ data.tar.gz: 0591a729fb07a42bcd4ea872e280d849f6eb1bea
5
5
  SHA512:
6
- metadata.gz: d9e23ab9e130aede68c68e7d65c07de1847585915af9794525db1057c3e3d6939010b73310fa7bf74ef808c94e41f41a41c7555af4d57bf96a1fb66548ee4bcc
7
- data.tar.gz: 36300571ab2f75ef5406e5a6dddef153370dd5718a08d2dfe262f5ac03b368034ed21f2e6e97d0607abb35880bb4f28feb255e79513bea8c5cc693ce5159f02a
6
+ metadata.gz: fa12a4235f2aa2b5d24f6a507e872d8509caa06c356de44cf564c528e73767f181ea8f7d5ec459e48b95c221992d767f5a00844e87eeab9894bd05e82231859b
7
+ data.tar.gz: a8543253d63c267ac33a7dbb9535f6465f97df093528ac181d84325bc3b14728a98bd88366adf6191c2a3db075e683d0752d76909c401fe326b7dd14f1d06e83
@@ -1 +1 @@
1
- 2.1.4
1
+ 2.2.0
@@ -60,12 +60,18 @@ command :list do |c|
60
60
 
61
61
  c.desc "Lists all activities"
62
62
  c.command :activities do |list_activities|
63
+ list_activities.flag [:limit],
64
+ arg_name: "NUMBER",
65
+ default_value: 10,
66
+ desc: "The number of activities to return"
67
+
63
68
  list_activities.flag [:with],
64
69
  arg_name: "NAME",
65
70
  desc: "List only activities involving the given friend"
66
71
 
67
72
  list_activities.action do |_, options|
68
- puts @introvert.list_activities(with: options[:with])
73
+ limit = options[:limit].to_i
74
+ puts @introvert.list_activities(limit: limit, with: options[:with])
69
75
  end
70
76
  end
71
77
  end
@@ -21,7 +21,8 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency "gli", "~> 2.12"
22
22
  spec.add_dependency "memoist", "~> 0.11"
23
23
 
24
- spec.add_development_dependency "rake", "~> 10.0"
25
24
  spec.add_development_dependency "bundler", "~> 1.7"
26
25
  spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4"
26
+ spec.add_development_dependency "minitest", "~> 5.5"
27
+ spec.add_development_dependency "rake", "~> 10.0"
27
28
  end
@@ -113,12 +113,20 @@ module Friends
113
113
  no_leading_asterisks = "(?<!\\*\\*)"
114
114
  no_ending_asterisks = "(?!\\*\\*)"
115
115
 
116
+ # We don't want to match names that are part of other words.
117
+ no_leading_alphabeticals = "(?<![A-z])"
118
+ no_ending_alphabeticals = "(?![A-z])"
119
+
116
120
  # Create the list of regexes and return it.
117
121
  chunks = name.split(Regexp.new(splitter))
118
122
 
119
123
  [chunks, [chunks.first]].map do |words|
120
124
  Regexp.new(
121
- no_leading_asterisks + words.join(splitter) + no_ending_asterisks,
125
+ no_leading_asterisks +
126
+ no_leading_alphabeticals +
127
+ words.join(splitter) +
128
+ no_ending_alphabeticals +
129
+ no_ending_asterisks,
122
130
  Regexp::IGNORECASE
123
131
  )
124
132
  end
@@ -48,12 +48,6 @@ module Friends
48
48
  filename
49
49
  end
50
50
 
51
- # List all friend names in the friends file.
52
- # @return [Array] a list of all friend names
53
- def list_friends
54
- friends.map(&:name)
55
- end
56
-
57
51
  # Add a friend and write out the new friends file.
58
52
  # @param name [String] the name of the friend to add
59
53
  # @raise [FriendsError] when a friend with that name is already in the file
@@ -75,31 +69,6 @@ module Friends
75
69
  friend # Return the added friend.
76
70
  end
77
71
 
78
- # List all activity details.
79
- # @param [String] the name of a friend to filter by, or nil for unfiltered
80
- # @return [Array] a list of all activity text values
81
- def list_activities(with:)
82
- acts = activities
83
-
84
- # Filter by friend name if argument is passed.
85
- unless with.nil?
86
- friends = friends_with_name_in(with)
87
-
88
- case friends.size
89
- when 1
90
- # If exactly one friend matches, use that friend to filter.
91
- acts = acts.select { |a| a.friend_names.include? friends.first.name }
92
- when 0 then raise FriendsError, "No friend found for \"#{with}\""
93
- else
94
- raise FriendsError,
95
- "More than one friend found for \"#{with}\": "\
96
- "#{friends.map(&:name).join(', ')}"
97
- end
98
- end
99
-
100
- acts.map(&:display_text)
101
- end
102
-
103
72
  # Add an activity and write out the new friends file.
104
73
  # @param serialization [String] the serialized activity
105
74
  # @return [Activity] the added activity
@@ -117,9 +86,15 @@ module Friends
117
86
  activity # Return the added activity.
118
87
  end
119
88
 
89
+ # List all friend names in the friends file.
90
+ # @return [Array] a list of all friend names
91
+ def list_friends
92
+ friends.map(&:name)
93
+ end
94
+
120
95
  # List your favorite friends.
121
- # @param num [Integer] the number of favorite friends to return, or nil if
122
- # unlimited
96
+ # @param limit [Integer] the number of favorite friends to return, or nil
97
+ # for no limit
123
98
  # @return [Array] a list of the favorite friends' names and activity
124
99
  # counts
125
100
  def list_favorites(limit:)
@@ -147,6 +122,37 @@ module Friends
147
122
  results.map(&:first)
148
123
  end
149
124
 
125
+ # List all activity details.
126
+ # @param limit [Integer] the number of activities to return, or nil for no
127
+ # limit
128
+ # @param with [String] the name of a friend to filter by, or nil for
129
+ # unfiltered
130
+ # @return [Array] a list of all activity text values
131
+ def list_activities(limit:, with:)
132
+ acts = activities
133
+
134
+ # Filter by friend name if argument is passed.
135
+ unless with.nil?
136
+ friends = friends_with_name_in(with)
137
+
138
+ case friends.size
139
+ when 1
140
+ # If exactly one friend matches, use that friend to filter.
141
+ acts = acts.select { |a| a.friend_names.include? friends.first.name }
142
+ when 0 then raise FriendsError, "No friend found for \"#{with}\""
143
+ else
144
+ raise FriendsError,
145
+ "More than one friend found for \"#{with}\": "\
146
+ "#{friends.map(&:name).join(', ')}"
147
+ end
148
+ end
149
+
150
+ # If we need to, trim the list.
151
+ acts = acts.take(limit) unless limit.nil?
152
+
153
+ acts.map(&:display_text)
154
+ end
155
+
150
156
  private
151
157
 
152
158
  # Gets the list of friends as read from the file.
@@ -1,3 +1,3 @@
1
1
  module Friends
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -112,6 +112,39 @@ describe Friends::Activity do
112
112
  activity.description.must_equal "Dinner with Elizabeth." # No match found.
113
113
  end
114
114
 
115
+ it "ignores when at beginning of word" do
116
+ activity = Friends::Activity.new(
117
+ date_s: Date.today.to_s,
118
+ description: "Field trip to the Johnson Co."
119
+ )
120
+ activity.highlight_friends(friends: friends)
121
+
122
+ # No match found.
123
+ activity.description.must_equal "Field trip to the Johnson Co."
124
+ end
125
+
126
+ it "ignores when in middle of word" do
127
+ activity = Friends::Activity.new(
128
+ date_s: Date.today.to_s,
129
+ description: "Field trip to the JimJohnJames Co."
130
+ )
131
+ activity.highlight_friends(friends: friends)
132
+
133
+ # No match found.
134
+ activity.description.must_equal "Field trip to the JimJohnJames Co."
135
+ end
136
+
137
+ it "ignores when at end of word" do
138
+ activity = Friends::Activity.new(
139
+ date_s: Date.today.to_s,
140
+ description: "Field trip to the JimJohn Co."
141
+ )
142
+ activity.highlight_friends(friends: friends)
143
+
144
+ # No match found.
145
+ activity.description.must_equal "Field trip to the JimJohn Co."
146
+ end
147
+
115
148
  it "does not match with leading asterisks" do
116
149
  activity = Friends::Activity.new(
117
150
  date_s: Date.today.to_s,
@@ -1,19 +1,19 @@
1
1
  require_relative "helper"
2
2
 
3
3
  describe Friends::Friend do
4
- let(:name) { "Jacob Evelyn" }
5
- let(:friend) { Friends::Friend.new(name: name) }
4
+ let(:friend_name) { "Jacob Evelyn" }
5
+ let(:friend) { Friends::Friend.new(name: friend_name) }
6
6
 
7
7
  describe ".deserialize" do
8
8
  subject { Friends::Friend.deserialize(serialized_str) }
9
9
 
10
10
  describe "when string is well-formed" do
11
11
  let(:serialized_str) do
12
- "#{Friends::Friend::SERIALIZATION_PREFIX}#{name}"
12
+ "#{Friends::Friend::SERIALIZATION_PREFIX}#{friend_name}"
13
13
  end
14
14
 
15
15
  it "creates a friend with the correct name" do
16
- subject.name.must_equal name
16
+ subject.name.must_equal friend_name
17
17
  end
18
18
  end
19
19
 
@@ -27,13 +27,17 @@ describe Friends::Friend do
27
27
  describe "#new" do
28
28
  subject { friend }
29
29
 
30
- it { subject.name.must_equal name }
30
+ it { subject.name.must_equal friend_name }
31
31
  end
32
32
 
33
33
  describe "#serialize" do
34
34
  subject { friend.serialize }
35
35
 
36
- it { subject.must_equal "#{Friends::Friend::SERIALIZATION_PREFIX}#{name}" }
36
+ it do
37
+ subject.must_equal(
38
+ "#{Friends::Friend::SERIALIZATION_PREFIX}#{friend_name}"
39
+ )
40
+ end
37
41
  end
38
42
 
39
43
  describe "#<=>" do
@@ -41,7 +41,7 @@ describe Friends::Introvert do
41
41
  subject { introvert.clean }
42
42
 
43
43
  # Delete the file that is created each time.
44
- after { File.delete(filename) }
44
+ after { File.delete(filename) if File.exists?(filename) }
45
45
 
46
46
  it "writes cleaned file" do
47
47
  sorted_friends = friends.sort
@@ -85,6 +85,9 @@ describe Friends::Introvert do
85
85
  let(:new_friend_name) { "Jacob Evelyn" }
86
86
  subject { introvert.add_friend(name: new_friend_name) }
87
87
 
88
+ # Delete the file that is created each time.
89
+ after { File.delete(filename) if File.exists?(filename) }
90
+
88
91
  describe "when there is no existing friend with that name" do
89
92
  it "adds the given friend" do
90
93
  introvert.stub(:friends, friends) do
@@ -112,7 +115,49 @@ describe Friends::Introvert do
112
115
  end
113
116
 
114
117
  describe "#list_activities" do
115
- subject { introvert.list_activities(with: with) }
118
+ subject { introvert.list_activities(limit: limit, with: with) }
119
+ let(:limit) { nil }
120
+ let(:with) { nil }
121
+
122
+ describe "when the limit is lower than the number of activities" do
123
+ let(:limit) { 1 }
124
+
125
+ it "lists that number of activities" do
126
+ introvert.stub(:activities, activities) do
127
+ subject.size.must_equal limit
128
+ end
129
+ end
130
+ end
131
+
132
+ describe "when the limit is equal to the number of activities" do
133
+ let(:limit) { activities.size }
134
+
135
+ it "lists all activities" do
136
+ introvert.stub(:activities, activities) do
137
+ subject.size.must_equal activities.size
138
+ end
139
+ end
140
+ end
141
+
142
+ describe "when the limit is greater than the number of activities" do
143
+ let(:limit) { activities.size + 5 }
144
+
145
+ it "lists all activities" do
146
+ introvert.stub(:activities, activities) do
147
+ subject.size.must_equal activities.size
148
+ end
149
+ end
150
+ end
151
+
152
+ describe "when the limit is nil" do
153
+ let(:limit) { nil }
154
+
155
+ it "lists all activities" do
156
+ introvert.stub(:activities, activities) do
157
+ subject.size.must_equal activities.size
158
+ end
159
+ end
160
+ end
116
161
 
117
162
  describe "when not filtering by a friend" do
118
163
  let(:with) { nil }
@@ -169,6 +214,9 @@ describe Friends::Introvert do
169
214
  let(:activity_description) { "Snorkeling with **Betsy Ross**." }
170
215
  subject { introvert.add_activity(serialization: activity_serialization) }
171
216
 
217
+ # Delete the file that is created each time.
218
+ after { File.delete(filename) if File.exists?(filename) }
219
+
172
220
  it "adds the given activity" do
173
221
  introvert.stub(:friends, friends) do
174
222
  subject
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friends
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Evelyn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-11 00:00:00.000000000 Z
11
+ date: 2015-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -39,47 +39,61 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.11'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '1.7'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '1.7'
55
55
  - !ruby/object:Gem::Dependency
56
- name: bundler
56
+ name: codeclimate-test-reporter
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.7'
61
+ version: '0.4'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.7'
68
+ version: '0.4'
69
69
  - !ruby/object:Gem::Dependency
70
- name: codeclimate-test-reporter
70
+ name: minitest
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.4'
75
+ version: '5.5'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.4'
82
+ version: '5.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
83
97
  description: Spend time with the people you care about. Introvert-tested. Extrovert-approved.
84
98
  email:
85
99
  - jacobevelyn@gmail.com
@@ -132,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
146
  version: '0'
133
147
  requirements: []
134
148
  rubyforge_project:
135
- rubygems_version: 2.2.2
149
+ rubygems_version: 2.4.5
136
150
  signing_key:
137
151
  specification_version: 4
138
152
  summary: Spend time with the people you care about.