friends 0.7 → 0.8

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: 31207f725992ac7187316680df58868b100dc206
4
- data.tar.gz: 15bffe0f9b8b706f0bb671b82e9fbd9dc73916bb
3
+ metadata.gz: 11ffd724b0c9aa013571f545c49efec501856191
4
+ data.tar.gz: efb5fa9791decbb6eb8fb050a2e1d61bd4aa913a
5
5
  SHA512:
6
- metadata.gz: 19450d3a00b67d617644fcffb4834222fefb195b8388e0334a89886e6fea06e220b8204e8be7c9406fe939c62b2c61696f62e4d90fd480a3779b1013912947d4
7
- data.tar.gz: ac9e03e6871c202fdfc53377d12678ee41ecf63d144d49d977dd1e31773e3b257a41e87e3f0e6e28c84874b6f1ddb47ca5d810a9a788ef66e3d4ba3cd2c7c4a2
6
+ metadata.gz: a6f3e3b822d68ec469ecd11ece0d9ea96838f7c95be0fcf7cff6fe17f47eea9900ab66b3c649f2690f0552bb533ff188ae5aafbbcedf37a2ced7fe3b0bcf408e
7
+ data.tar.gz: ed8468dea41326b0a221960bf9efe5b67707b840479a9a2a9be6014bc16e11fe490fc2786f337a1fa8f86b0fd45375a4d03d2b5f5a8944caf19b6ae4a1a5d559
@@ -1,3 +1,5 @@
1
1
  PreCommit:
2
2
  Reek:
3
3
  enabled: false
4
+ RuboCop:
5
+ enabled: true
@@ -1,5 +1,21 @@
1
1
  # Change Log
2
2
 
3
+ ## [v0.8](https://github.com/JacobEvelyn/friends/tree/v0.8) (2016-01-06)
4
+ [Full Changelog](https://github.com/JacobEvelyn/friends/compare/v0.7...v0.8)
5
+
6
+ **Implemented enhancements:**
7
+
8
+ - Reference friends by real name or nickname [\#40](https://github.com/JacobEvelyn/friends/issues/40)
9
+
10
+ **Merged pull requests:**
11
+
12
+ - Fix nicknames bug and add README documentation [\#54](https://github.com/JacobEvelyn/friends/pull/54) ([JacobEvelyn](https://github.com/JacobEvelyn))
13
+ - Add basic nickname support [\#53](https://github.com/JacobEvelyn/friends/pull/53) ([JacobEvelyn](https://github.com/JacobEvelyn))
14
+ - Add CHANGELOG.md and RELEASING.md [\#52](https://github.com/JacobEvelyn/friends/pull/52) ([JacobEvelyn](https://github.com/JacobEvelyn))
15
+ - Update Code of Conduct [\#51](https://github.com/JacobEvelyn/friends/pull/51) ([JacobEvelyn](https://github.com/JacobEvelyn))
16
+ - Improve contributing documentation [\#50](https://github.com/JacobEvelyn/friends/pull/50) ([JacobEvelyn](https://github.com/JacobEvelyn))
17
+ - Add badgefury.io badge [\#49](https://github.com/JacobEvelyn/friends/pull/49) ([JacobEvelyn](https://github.com/JacobEvelyn))
18
+
3
19
  ## [v0.7](https://github.com/JacobEvelyn/friends/tree/v0.7) (2016-01-05)
4
20
  [Full Changelog](https://github.com/JacobEvelyn/friends/compare/v0.6...v0.7)
5
21
 
@@ -32,21 +48,62 @@
32
48
  - Make activities on same day chronologically ordered [\#38](https://github.com/JacobEvelyn/friends/pull/38) ([JacobEvelyn](https://github.com/JacobEvelyn))
33
49
 
34
50
  ## [v0.4](https://github.com/JacobEvelyn/friends/tree/v0.4) (2015-11-14)
51
+ [Full Changelog](https://github.com/JacobEvelyn/friends/compare/v0.3...v0.4)
52
+
53
+ ## [v0.3](https://github.com/JacobEvelyn/friends/tree/v0.3) (2015-11-11)
54
+ [Full Changelog](https://github.com/JacobEvelyn/friends/compare/v0.2...v0.3)
55
+
35
56
  **Implemented enhancements:**
36
57
 
37
58
  - Be able to enter activity with normal prompt [\#34](https://github.com/JacobEvelyn/friends/issues/34)
59
+ - Create file if none exists [\#25](https://github.com/JacobEvelyn/friends/issues/25)
60
+ - Friends should be able to have nicknames [\#17](https://github.com/JacobEvelyn/friends/issues/17)
61
+ - Add ability to change friend name [\#16](https://github.com/JacobEvelyn/friends/issues/16)
62
+ - Auto-update? [\#8](https://github.com/JacobEvelyn/friends/issues/8)
63
+
64
+ ## [v0.2](https://github.com/JacobEvelyn/friends/tree/v0.2) (2015-11-08)
65
+ [Full Changelog](https://github.com/JacobEvelyn/friends/compare/v0.1...v0.2)
66
+
67
+ ## [v0.1](https://github.com/JacobEvelyn/friends/tree/v0.1) (2015-11-03)
68
+ [Full Changelog](https://github.com/JacobEvelyn/friends/compare/v0.0.6...v0.1)
69
+
70
+ ## [v0.0.6](https://github.com/JacobEvelyn/friends/tree/v0.0.6) (2015-06-28)
71
+ [Full Changelog](https://github.com/JacobEvelyn/friends/compare/v0.0.5...v0.0.6)
72
+
73
+ **Implemented enhancements:**
74
+
75
+ - Have robustness around name extraction from activities [\#21](https://github.com/JacobEvelyn/friends/issues/21)
76
+
77
+ ## [v0.0.5](https://github.com/JacobEvelyn/friends/tree/v0.0.5) (2015-06-28)
78
+ [Full Changelog](https://github.com/JacobEvelyn/friends/compare/v0.0.4...v0.0.5)
79
+
80
+ ## [v0.0.4](https://github.com/JacobEvelyn/friends/tree/v0.0.4) (2015-06-01)
81
+ [Full Changelog](https://github.com/JacobEvelyn/friends/compare/v0.0.3...v0.0.4)
82
+
83
+ **Merged pull requests:**
84
+
85
+ - Bump version to 0.0.3 [\#33](https://github.com/JacobEvelyn/friends/pull/33) ([JacobEvelyn](https://github.com/JacobEvelyn))
86
+
87
+ ## [v0.0.3](https://github.com/JacobEvelyn/friends/tree/v0.0.3) (2015-05-28)
88
+ [Full Changelog](https://github.com/JacobEvelyn/friends/compare/v0.0.2...v0.0.3)
89
+
90
+ **Merged pull requests:**
91
+
92
+ - Allow limiting of activity lists [\#32](https://github.com/JacobEvelyn/friends/pull/32) ([JacobEvelyn](https://github.com/JacobEvelyn))
93
+ - Improve friend matching code [\#31](https://github.com/JacobEvelyn/friends/pull/31) ([JacobEvelyn](https://github.com/JacobEvelyn))
94
+
95
+ ## [v0.0.2](https://github.com/JacobEvelyn/friends/tree/v0.0.2) (2015-01-11)
96
+ [Full Changelog](https://github.com/JacobEvelyn/friends/compare/v0.0.1...v0.0.2)
97
+
98
+ **Implemented enhancements:**
99
+
38
100
  - Add confirmation after commands \(and --quiet\) [\#28](https://github.com/JacobEvelyn/friends/issues/28)
39
101
  - Have activity dates default to today if none provided [\#27](https://github.com/JacobEvelyn/friends/issues/27)
40
- - Create file if none exists [\#25](https://github.com/JacobEvelyn/friends/issues/25)
41
102
  - Add more detailed usage example to README. [\#23](https://github.com/JacobEvelyn/friends/issues/23)
42
- - Have robustness around name extraction from activities [\#21](https://github.com/JacobEvelyn/friends/issues/21)
43
103
  - Put activities before friends in friends.md [\#20](https://github.com/JacobEvelyn/friends/issues/20)
44
104
  - Friend name lookups should be case-insensitive [\#18](https://github.com/JacobEvelyn/friends/issues/18)
45
- - Friends should be able to have nicknames [\#17](https://github.com/JacobEvelyn/friends/issues/17)
46
- - Add ability to change friend name [\#16](https://github.com/JacobEvelyn/friends/issues/16)
47
105
  - Add link to RubyDoc in README [\#12](https://github.com/JacobEvelyn/friends/issues/12)
48
106
  - Release to RubyGems [\#10](https://github.com/JacobEvelyn/friends/issues/10)
49
- - Auto-update? [\#8](https://github.com/JacobEvelyn/friends/issues/8)
50
107
  - Gracefully handle friend name conflicts in all commands [\#7](https://github.com/JacobEvelyn/friends/issues/7)
51
108
  - Be able to list activities [\#6](https://github.com/JacobEvelyn/friends/issues/6)
52
109
  - Be able to add activities [\#5](https://github.com/JacobEvelyn/friends/issues/5)
@@ -57,9 +114,6 @@
57
114
 
58
115
  **Merged pull requests:**
59
116
 
60
- - Bump version to 0.0.3 [\#33](https://github.com/JacobEvelyn/friends/pull/33) ([JacobEvelyn](https://github.com/JacobEvelyn))
61
- - Allow limiting of activity lists [\#32](https://github.com/JacobEvelyn/friends/pull/32) ([JacobEvelyn](https://github.com/JacobEvelyn))
62
- - Improve friend matching code [\#31](https://github.com/JacobEvelyn/friends/pull/31) ([JacobEvelyn](https://github.com/JacobEvelyn))
63
117
  - Improve documentation [\#30](https://github.com/JacobEvelyn/friends/pull/30) ([JacobEvelyn](https://github.com/JacobEvelyn))
64
118
  - Add confirm messages and --quiet switch [\#29](https://github.com/JacobEvelyn/friends/pull/29) ([JacobEvelyn](https://github.com/JacobEvelyn))
65
119
  - Put activities above friends in file [\#26](https://github.com/JacobEvelyn/friends/pull/26) ([JacobEvelyn](https://github.com/JacobEvelyn))
@@ -72,6 +126,7 @@
72
126
  - Clean up gemspec dependencies [\#11](https://github.com/JacobEvelyn/friends/pull/11) ([JacobEvelyn](https://github.com/JacobEvelyn))
73
127
  - Clean up README [\#9](https://github.com/JacobEvelyn/friends/pull/9) ([JacobEvelyn](https://github.com/JacobEvelyn))
74
128
 
129
+ ## [v0.0.1](https://github.com/JacobEvelyn/friends/tree/v0.0.1) (2014-12-11)
75
130
 
76
131
 
77
132
  \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
@@ -35,7 +35,7 @@ This Code of Conduct applies both within project spaces and in public spaces
35
35
  when an individual is representing the project or its community.
36
36
 
37
37
  Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
- reported by contacting a project maintainer at [INSERT EMAIL ADDRESS]. All
38
+ reported by contacting a project maintainer at jacobevelyn@gmail.com. All
39
39
  complaints will be reviewed and investigated and will result in a response that
40
40
  is deemed necessary and appropriate to the circumstances. Maintainers are
41
41
  obligated to maintain confidentiality with regard to the reporter of an
@@ -0,0 +1,61 @@
1
+ # Contributing
2
+
3
+ If you're reading this, it means you want to contribute to this project. Hooray!
4
+
5
+ Here's what to do:
6
+
7
+ 1. If you're looking for a task to work on, check the
8
+ ["up-for-grabs" Issues](https://github.com/JacobEvelyn/friends/labels/upforgrabs). If you see something there that catches your
9
+ eye, leave a comment indicating you'll work on it and
10
+ it's yours! If you already have something to work on,
11
+ that's great as well!
12
+ 2. Fork the repository (https://github.com/JacobEvelyn/friends/fork).
13
+ 3. Clone your forked repository.
14
+ 4. From within the repository directory, run:
15
+ `bundle install && overcommit --install`
16
+ 5. Create your feature branch
17
+ (`git checkout -b my-new-feature`).
18
+ 6. Make your changes. Add or modify tests if necessary!
19
+ (Run tests with `rake test`.) Do your best to conform to
20
+ existing style and commenting patterns.
21
+ 7. Commit your changes
22
+ (`git commit -am "Add some feature"`). You should see
23
+ output from
24
+ [`overcommit`](https://github.com/brigade/overcommit) as
25
+ it runs commit hooks that looks something like this:
26
+
27
+ ```
28
+ Running pre-commit hooks
29
+ Analyzing with RuboCop......................................[RuboCop] OK
30
+
31
+ ✓ All pre-commit hooks passed
32
+
33
+ Running commit-msg hooks
34
+ Checking subject capitalization..................[CapitalizedSubject] OK
35
+ Checking subject line.............................[SingleLineSubject] OK
36
+ Checking text width.......................................[TextWidth] OK
37
+ Checking for trailing periods in subject.............[TrailingPeriod] OK
38
+
39
+ ✓ All commit-msg hooks passed
40
+ ```
41
+
42
+ If any of the commit hook checks fail, fix them if you
43
+ can but don't hesitate to reach out if you don't know
44
+ how! This practice is meant to keep the code clean but
45
+ it shouldn't be scary and it's totally fine to need
46
+ help!
47
+ 8. Push your changes to GitHub, and open a Pull Request.
48
+ 9. Your code will be reviewed and merged as quickly as
49
+ possible!
50
+ 10. Check yourself out on the [contributors page](https://github.com/JacobEvelyn/friends/graphs/contributors)! Look at how cool you are!
51
+
52
+ If you have any questions at all or get stuck on any step,
53
+ don't hesitate to
54
+ [open a GitHub Issue](https://github.com/JacobEvelyn/friends/issues/new)!
55
+ I'll respond as quickly as I can, and I'm friendly! I
56
+ promise I don't bite. 😊
57
+
58
+ ## Code of Conduct
59
+
60
+ Note that this project follows a [Code of Conduct](https://github.com/JacobEvelyn/friends/blob/master/CODE_OF_CONDUCT.md).
61
+ If you're a polite, reasonable person you won't have any issues!
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Code Climate](https://codeclimate.com/github/JacobEvelyn/friends/badges/gpa.svg)](https://codeclimate.com/github/JacobEvelyn/friends) [![Test Coverage](https://codeclimate.com/github/JacobEvelyn/friends/badges/coverage.svg)](https://codeclimate.com/github/JacobEvelyn/friends) [![Build Status](https://travis-ci.org/JacobEvelyn/friends.svg)](https://travis-ci.org/JacobEvelyn/friends) [![Inline docs](http://inch-ci.org/github/JacobEvelyn/friends.png)](http://inch-ci.org/github/JacobEvelyn/friends) [![ghit.me](https://ghit.me/badge.svg?repo=JacobEvelyn/friends)](https://ghit.me/repo/JacobEvelyn/friends)
1
+ [![Gem Version](https://badge.fury.io/rb/friends.svg)](https://badge.fury.io/rb/friends) [![Code Climate](https://codeclimate.com/github/JacobEvelyn/friends/badges/gpa.svg)](https://codeclimate.com/github/JacobEvelyn/friends) [![Test Coverage](https://codeclimate.com/github/JacobEvelyn/friends/badges/coverage.svg)](https://codeclimate.com/github/JacobEvelyn/friends) [![Build Status](https://travis-ci.org/JacobEvelyn/friends.svg)](https://travis-ci.org/JacobEvelyn/friends) [![Inline docs](http://inch-ci.org/github/JacobEvelyn/friends.png)](http://inch-ci.org/github/JacobEvelyn/friends) [![ghit.me](https://ghit.me/badge.svg?repo=JacobEvelyn/friends)](https://ghit.me/repo/JacobEvelyn/friends)
2
2
 
3
3
  # Friends
4
4
 
@@ -38,7 +38,6 @@ $ gem install friends
38
38
  ### Basic commands:
39
39
 
40
40
  ##### Add a friend:
41
-
42
41
  ```
43
42
  $ friends add friend "Grace Hopper"
44
43
  Friend added: "Grace Hopper"
@@ -65,6 +64,24 @@ You can escape the names of friends you don't want `friends` to match with a bac
65
64
  $ friends add activity "2015-11-01: Grace and I went to \Marie's Diner. \George had to cancel at the last minute."
66
65
  Activity added: "2015-11-01: Grace Hopper and I went to Marie's Diner. George had to cancel at the last minute."
67
66
  ```
67
+ ##### Set a friend's nicknames:
68
+ ```
69
+ $ friends add nickname "Grace Hopper" "The Admiral"
70
+ Nickname added: "Grace Hopper (a.k.a. The Admiral)
71
+ $ friends add nickname "Grace Hopper" "Amazing Grace"
72
+ Nickname added: "Grace Hopper (a.k.a. The Admiral a.k.a. Amazing Grace)"
73
+ ```
74
+ Nicknames will be used to match friends in activities,
75
+ just like formal names:
76
+ ```
77
+ $ friends add activity "Invented debugging with Amazing Grace.""
78
+ Activity added: "2016-01-06: Invented debugging with Amazing Grace Hopper."
79
+ ```
80
+ And they can be removed as well:
81
+ ```
82
+ $ friends remove nickname "Grace Hopper" "The Admiral"
83
+ Nickname removed: "Grace Hopper (a.k.a. Amazing Grace)"
84
+ ```
68
85
  ##### Suggest a friend to do something with:
69
86
  ```
70
87
  $ friends suggest
@@ -185,18 +202,16 @@ In case you're *really* interested, we have
185
202
  If you have an idea,
186
203
  [make a GitHub Issue](https://github.com/JacobEvelyn/friends/issues/new)!
187
204
  Suggestions are very very welcome, and usually are implemented very
188
- quickly. And if you'd like to do the implementing yourself:
189
-
190
- 1. Fork it (https://github.com/JacobEvelyn/friends/fork)
191
- 2. Create your feature branch (`git checkout -b my-new-feature`)
192
- 3. Commit your changes (`git commit -am "Add some feature"`)
193
- 4. Push to the branch (`git push origin my-new-feature`)
194
- 5. Create a new Pull Request
195
-
196
- **Make sure your changes have appropriate tests (`rake test`) and
197
- conform to the Rubocop style specified. This project uses
198
- [overcommit](https://github.com/brigade/overcommit) to enforce good
199
- code.**
205
+ quickly. And if you'd like to do the implementing yourself, see the
206
+ [contributing guide](https://github.com/JacobEvelyn/friends/blob/master/CONTRIBUTING.md).
207
+
208
+ A big big thanks to all of this project's lovely
209
+ [contributors](https://github.com/JacobEvelyn/friends/graphs/contributors)!
210
+
211
+ ## Code of Conduct
212
+
213
+ Note that this project follows a [Code of Conduct](https://github.com/JacobEvelyn/friends/blob/master/CODE_OF_CONDUCT.md).
214
+ If you're a polite, reasonable person you won't have any issues!
200
215
 
201
216
  ## License
202
217
 
@@ -0,0 +1,13 @@
1
+ # Releasing
2
+
3
+ These are steps for the maintainer to take to release a new version of this gem.
4
+
5
+ 1. On the `master` branch, update the `VERSION` constant in
6
+ `lib/friends/version.rb`.
7
+ 2. Commit the change (`git commit -m 'Bump to vX.X'`).
8
+ 3. Add a tag (`git tag -am "vX.X" vX.X`).
9
+ 4. `git push && git push --tags`
10
+ 5. `github_changelog_generator && git commit -m 'Update CHANGELOG for vX.X'`
11
+ 6. `git push`
12
+ 7. `gem build friends.gemspec && gem push *.gem && rm *.gem`
13
+ 8. Celebrate!
@@ -35,6 +35,7 @@ switch [:clean],
35
35
  negatable: false,
36
36
  desc: "Force a clean write of the friends file"
37
37
 
38
+ desc "Updates the `friends` program"
38
39
  command :update do |update|
39
40
  update.action do
40
41
  search = `gem search friends`
@@ -126,9 +127,30 @@ command :add do |add|
126
127
  @message = "Activity added: \"#{activity.display_text}\""
127
128
  end
128
129
  end
130
+
131
+ add.desc "Adds a nickname to a friend"
132
+ add.arg_name "NAME NICKNAME"
133
+ add.command :nickname do |add_nickname|
134
+ add_nickname.action do |_, _, args|
135
+ friend = @introvert.add_nickname(name: args.first, nickname: args[1])
136
+ @message = "Nickname added: \"#{friend}\""
137
+ end
138
+ end
139
+ end
140
+
141
+ desc "Remove a nickname"
142
+ command :remove do |remove|
143
+ remove.desc "Removes a nickname from a friend"
144
+ remove.arg_name "NAME NICKNAME"
145
+ remove.command :nickname do |remove_nickname|
146
+ remove_nickname.action do |_, _, args|
147
+ friend = @introvert.remove_nickname(name: args.first, nickname: args[1])
148
+ @message = "Nickname removed: \"#{friend}\""
149
+ end
150
+ end
129
151
  end
130
152
 
131
- desc "Graph"
153
+ desc "Graph a friend's relationship over time"
132
154
  arg_name "NAME"
133
155
  command :graph do |graph|
134
156
  graph.action do |_, _, args|
@@ -153,7 +175,7 @@ command :graph do |graph|
153
175
  end
154
176
  end
155
177
 
156
- desc "Suggest"
178
+ desc "Suggest friends to do activities with"
157
179
  command :suggest do |suggest|
158
180
  suggest.action do
159
181
  suggestions = @introvert.suggest
@@ -28,5 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "bundler", "~> 1.6"
29
29
  spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4"
30
30
  spec.add_development_dependency "minitest", "~> 5.5"
31
+ spec.add_development_dependency "overcommit", "~> 0.30"
31
32
  spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rubocop", "~> 0.35"
32
34
  end
data/friends.md CHANGED
@@ -6,5 +6,5 @@
6
6
 
7
7
  ### Friends:
8
8
  - George Washington Carver
9
- - Grace Hopper
9
+ - Grace Hopper (a.k.a. The Admiral)
10
10
  - Marie Curie
@@ -7,10 +7,11 @@ module Friends
7
7
  extend Serializable
8
8
 
9
9
  SERIALIZATION_PREFIX = "- "
10
+ NICKNAME_PREFIX = "a.k.a. "
10
11
 
11
12
  # @return [Regexp] the regex for capturing groups in deserialization
12
13
  def self.deserialization_regex
13
- /(#{SERIALIZATION_PREFIX})?(?<name>.+)/
14
+ /(#{SERIALIZATION_PREFIX})?(?<name>[^\(]+)(\((?<nickname_str>#{NICKNAME_PREFIX}.+)\))?/
14
15
  end
15
16
 
16
17
  # @return [Regexp] the string of what we expected during deserialization
@@ -19,15 +20,43 @@ module Friends
19
20
  end
20
21
 
21
22
  # @param name [String] the name of the friend
22
- def initialize(name:)
23
- @name = name
23
+ def initialize(name:, nickname_str: nil)
24
+ @name = name.strip
25
+ @nicknames = nickname_str &&
26
+ nickname_str.split(NICKNAME_PREFIX)[1..-1].map(&:strip) ||
27
+ []
24
28
  end
25
29
 
26
30
  attr_accessor :name
27
31
 
28
32
  # @return [String] the file serialization text for the friend
29
33
  def serialize
30
- "#{SERIALIZATION_PREFIX}#{name}"
34
+ "#{SERIALIZATION_PREFIX}#{to_s}"
35
+ end
36
+
37
+ # @return [String] a string representing the friend's name and nicknames
38
+ def to_s
39
+ return name if @nicknames.empty?
40
+
41
+ nickname_str = @nicknames.map { |n| "#{NICKNAME_PREFIX}#{n}" }.join(" ")
42
+ "#{name} (#{nickname_str})"
43
+ end
44
+
45
+ # Adds a nickname, avoiding duplicates and stripping surrounding whitespace.
46
+ # @param nickname [String] the nickname to add
47
+ def add_nickname(nickname)
48
+ @nicknames << nickname
49
+ @nicknames.uniq!
50
+ end
51
+
52
+ # @param nickname [String] the nickname to remove
53
+ # @return [Boolean] true if the nickname was present, false otherwise
54
+ def remove_nickname(nickname)
55
+ unless @nicknames.include? nickname
56
+ raise FriendsError, "Nickname \"#{nickname}\" not found for \"#{name}\""
57
+ end
58
+
59
+ @nicknames.delete(nickname)
31
60
  end
32
61
 
33
62
  # The number of activities this friend is in. This is for internal use only
@@ -74,7 +103,7 @@ module Friends
74
103
  # Create the list of regexes and return it.
75
104
  chunks = name.split(Regexp.new(splitter))
76
105
 
77
- [chunks, [chunks.first]].map do |words|
106
+ [chunks, [chunks.first], *@nicknames.map { |n| [n] }].map do |words|
78
107
  Regexp.new(
79
108
  no_leading_backslash +
80
109
  no_leading_asterisks +
@@ -89,6 +89,35 @@ module Friends
89
89
  activity # Return the added activity.
90
90
  end
91
91
 
92
+ # Add a nickname to an existing friend and write out the new friends file.
93
+ # @param name [String] the name of the friend
94
+ # @param nickname [String] the nickname to add to the friend
95
+ # @raise [FriendsError] if 0 of 2+ friends match the given name
96
+ # @return [Friend] the existing friend
97
+ def add_nickname(name:, nickname:)
98
+ friend = friend_with_name_in(name)
99
+ friend.add_nickname(nickname.strip)
100
+
101
+ clean # Write a cleaned file.
102
+
103
+ friend
104
+ end
105
+
106
+ # Remove a nickname from an existing friend and write out the new friends
107
+ # file.
108
+ # @param name [String] the name of the friend
109
+ # @param nickname [String] the nickname to remove from the friend
110
+ # @raise [FriendsError] if 0 of 2+ friends match the given name
111
+ # @return [Friend] the existing friend
112
+ def remove_nickname(name:, nickname:)
113
+ friend = friend_with_name_in(name)
114
+ friend.remove_nickname(nickname.strip)
115
+
116
+ clean # Write a cleaned file.
117
+
118
+ friend
119
+ end
120
+
92
121
  # List all friend names in the friends file.
93
122
  # @return [Array] a list of all friend names
94
123
  def list_friends
@@ -127,6 +156,7 @@ module Friends
127
156
  # @param with [String] the name of a friend to filter by, or nil for
128
157
  # unfiltered
129
158
  # @return [Array] a list of all activity text values
159
+ # @raise [FriendsError] if 0 of 2+ friends match the given `with` text
130
160
  def list_activities(limit:, with:)
131
161
  acts = @activities
132
162
 
@@ -153,6 +183,7 @@ module Friends
153
183
  # The keys of the hash are all of the months (inclusive) between the first
154
184
  # and last month in which activities for the given friend have been
155
185
  # recorded.
186
+ # @raise [FriendsError] if 0 of 2+ friends match the given name
156
187
  def graph(name:)
157
188
  friend = friend_with_name_in(name) # Find the friend by name.
158
189
 
@@ -1,3 +1,3 @@
1
1
  module Friends
2
- VERSION = "0.7"
2
+ VERSION = "0.8"
3
3
  end
@@ -40,6 +40,45 @@ describe Friends::Friend do
40
40
  end
41
41
  end
42
42
 
43
+ describe "#add_nickname" do
44
+ subject { friend.add_nickname("The Dude") }
45
+
46
+ it "adds the nickname" do
47
+ subject
48
+ friend.instance_variable_get(:@nicknames).must_include("The Dude")
49
+ end
50
+
51
+ it "does not keep duplicates" do
52
+ # Add the same nickname twice. Do not use `subject` because it's memoized.
53
+ friend.add_nickname("The Dude")
54
+ friend.add_nickname("The Dude")
55
+
56
+ friend.instance_variable_get(:@nicknames).must_equal ["The Dude"]
57
+ end
58
+ end
59
+
60
+ describe "#remove_nickname" do
61
+ subject { friend.remove_nickname("Jake") }
62
+
63
+ describe "when the nickname is present" do
64
+ let(:friend) do
65
+ Friends::Friend.new(name: friend_name, nickname_str: "a.k.a. Jake")
66
+ end
67
+
68
+ it "removes the nickname" do
69
+ friend.instance_variable_get(:@nicknames).must_equal ["Jake"]
70
+ subject
71
+ friend.instance_variable_get(:@nicknames).must_equal []
72
+ end
73
+ end
74
+
75
+ describe "when the nickname is not present" do
76
+ it "raises an error if the nickname is not found" do
77
+ proc { subject }.must_raise Friends::FriendsError
78
+ end
79
+ end
80
+ end
81
+
43
82
  describe "#n_activities" do
44
83
  subject { friend.n_activities }
45
84
 
@@ -255,6 +255,37 @@ describe Friends::Introvert do
255
255
  end
256
256
  end
257
257
 
258
+ describe "#add_nickname" do
259
+ subject do
260
+ introvert.add_nickname(name: friend_names.first, nickname: "The Dude")
261
+ end
262
+
263
+ # Delete the file that is created each time.
264
+ after { File.delete(filename) if File.exists?(filename) }
265
+
266
+ it "returns the modified friend" do
267
+ stub_friends(friends) do
268
+ subject.must_equal friends.first
269
+ end
270
+ end
271
+ end
272
+
273
+ describe "#remove_nickname" do
274
+ subject do
275
+ introvert.remove_nickname(name: "Jeff", nickname: "The Dude")
276
+ end
277
+
278
+ # Delete the file that is created each time.
279
+ after { File.delete(filename) if File.exists?(filename) }
280
+
281
+ it "returns the modified friend" do
282
+ friend = Friends::Friend.new(name: "Jeff", nickname_str: "a.k.a. The Dude")
283
+ stub_friends([friend]) do
284
+ subject.must_equal friend
285
+ end
286
+ end
287
+ end
288
+
258
289
  describe "#list_favorites" do
259
290
  subject { introvert.list_favorites(limit: limit) }
260
291
 
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.7'
4
+ version: '0.8'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Evelyn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-05 00:00:00.000000000 Z
11
+ date: 2016-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '5.5'
97
+ - !ruby/object:Gem::Dependency
98
+ name: overcommit
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.30'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.30'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rake
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +122,20 @@ dependencies:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
124
  version: '10.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.35'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.35'
111
139
  description: Spend time with the people you care about. Introvert-tested. Extrovert-approved.
112
140
  email:
113
141
  - jacobevelyn@gmail.com
@@ -123,9 +151,11 @@ files:
123
151
  - ".travis.yml"
124
152
  - CHANGELOG.md
125
153
  - CODE_OF_CONDUCT.md
154
+ - CONTRIBUTING.md
126
155
  - Gemfile
127
156
  - LICENSE.txt
128
157
  - README.md
158
+ - RELEASING.md
129
159
  - Rakefile
130
160
  - bin/friends
131
161
  - friends.gemspec