friends 0.0.6 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/bin/friends +24 -2
- data/lib/friends/activity.rb +4 -4
- data/lib/friends/introvert.rb +31 -0
- data/lib/friends/serializable.rb +1 -1
- data/lib/friends/version.rb +1 -1
- data/test/activity_spec.rb +4 -2
- data/test/introvert_spec.rb +16 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 594e797cfad3741eac04b32f65fad9bdaa79e6d6
|
4
|
+
data.tar.gz: d4db59517521f8d5110b85426533d8a199db2d75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dc7bb05e42a152f8fc5e5d532069295525bceb3c5f30b8a35cbf9b32dcd8561644d947f205a5a0cb964b4d1a2ae084bc745ee14bfa1e48daeb1c880130cf4fe
|
7
|
+
data.tar.gz: e675e071c9be2c956c7d138c327ef15a5c20823643480b754304d7ef9b219159d8de3c853351d054fd9648a0bdd519691be8bafea31d87cb9cbf1dcef6d160e6
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.2.
|
1
|
+
2.2.2
|
data/bin/friends
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
# Todo:
|
4
|
+
# - Allow easy editing of most recent entry.
|
5
|
+
# - Make automatching use context better. (David & Meryl vs. David & Patricia)
|
6
|
+
# - Allow escape char to prevent automatching. ("\Zane wasn't there.")
|
7
|
+
|
3
8
|
require "gli"
|
9
|
+
require "minitest/pride"
|
4
10
|
|
5
11
|
require "friends/introvert"
|
6
12
|
require "friends/version"
|
@@ -105,12 +111,28 @@ arg_name "NAME"
|
|
105
111
|
command :graph do |graph|
|
106
112
|
graph.action do |_, _, args|
|
107
113
|
data = @introvert.graph(name: args.first)
|
114
|
+
|
108
115
|
data.each do |month, count|
|
109
|
-
|
116
|
+
print "#{month} |"
|
117
|
+
|
118
|
+
colorer = Minitest::PrideLOL.new($stdout)
|
119
|
+
count.times { print colorer.pride "█" }
|
120
|
+
puts
|
110
121
|
end
|
111
122
|
end
|
112
123
|
end
|
113
124
|
|
125
|
+
desc "Suggest"
|
126
|
+
command :suggest do |suggest|
|
127
|
+
suggest.action do
|
128
|
+
suggestions = @introvert.suggest
|
129
|
+
|
130
|
+
puts "Distant friend: \e[1m#{suggestions[:distant].sample}\e[0m"
|
131
|
+
puts "Moderate friend: \e[1m#{suggestions[:moderate].sample}\e[0m"
|
132
|
+
puts "Close friend: \e[1m#{suggestions[:close].sample}\e[0m"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
114
136
|
desc "Cleans your friends.md file"
|
115
137
|
command :clean do |clean|
|
116
138
|
clean.action do
|
@@ -145,5 +167,5 @@ on_error do |error|
|
|
145
167
|
abort "Error: #{error}"
|
146
168
|
end
|
147
169
|
|
148
|
-
# Run the program and return the exit code corresponding to
|
170
|
+
# Run the program and return the exit code corresponding to its success.
|
149
171
|
exit run(ARGV)
|
data/lib/friends/activity.rb
CHANGED
@@ -13,7 +13,7 @@ module Friends
|
|
13
13
|
|
14
14
|
# @return [Regexp] the regex for capturing groups in deserialization
|
15
15
|
def self.deserialization_regex
|
16
|
-
/(#{SERIALIZATION_PREFIX})?((?<date_s>\d{4}-\d\d-\d\d):\s)?(?<description>.+)
|
16
|
+
/(#{SERIALIZATION_PREFIX})?((?<date_s>\d{4}-\d\d-\d\d)(:\s)?)?(?<description>.+)?/
|
17
17
|
end
|
18
18
|
|
19
19
|
# @return [Regexp] the string of what we expected during deserialization
|
@@ -24,18 +24,18 @@ module Friends
|
|
24
24
|
# @param date_s [String] the activity's date, parsed using Date.parse()
|
25
25
|
# @param description [String] the activity's description
|
26
26
|
# @return [Activity] the new activity
|
27
|
-
def initialize(date_s: Date.today.to_s, description:)
|
27
|
+
def initialize(date_s: Date.today.to_s, description: nil)
|
28
28
|
@date = Date.parse(date_s)
|
29
29
|
@description = description
|
30
30
|
end
|
31
31
|
|
32
32
|
attr_reader :date
|
33
|
-
|
33
|
+
attr_accessor :description
|
34
34
|
|
35
35
|
# @return [String] the command-line display text for the activity
|
36
36
|
def display_text
|
37
37
|
date_s = "\e[1m#{date}\e[0m"
|
38
|
-
description_s = description
|
38
|
+
description_s = description.to_s
|
39
39
|
while match = description_s.match(/(\*\*)([^\*]+)(\*\*)/)
|
40
40
|
description_s =
|
41
41
|
"#{match.pre_match}\e[1m#{match[2]}\e[0m#{match.post_match}"
|
data/lib/friends/introvert.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
# able to be used directly within another Ruby program, without needing to call
|
3
3
|
# the command-line script explicitly.
|
4
4
|
|
5
|
+
require "readline"
|
6
|
+
|
5
7
|
require "friends/activity"
|
6
8
|
require "friends/friend"
|
7
9
|
require "friends/friends_error"
|
@@ -80,6 +82,9 @@ module Friends
|
|
80
82
|
raise FriendsError, e
|
81
83
|
end
|
82
84
|
|
85
|
+
# If there's no description, prompt the user for one.
|
86
|
+
activity.description ||= Readline.readline(activity.display_text)
|
87
|
+
|
83
88
|
activity.highlight_friends(introvert: self, friends: friends)
|
84
89
|
activities << activity
|
85
90
|
clean # Write a cleaned file.
|
@@ -174,6 +179,32 @@ module Friends
|
|
174
179
|
act_table
|
175
180
|
end
|
176
181
|
|
182
|
+
# @return [Hash] of the format:
|
183
|
+
# {
|
184
|
+
# distant: ["Distant Friend 1 Name", "Distant Friend 2 Name", ...],
|
185
|
+
# moderate: ["Moderate Friend 1 Name", "Moderate Friend 2 Name", ...],
|
186
|
+
# close: ["Close Friend 1 Name", "Close Friend 2 Name", ...]
|
187
|
+
# }
|
188
|
+
def suggest
|
189
|
+
set_n_activities! # Set n_activities for all friends.
|
190
|
+
|
191
|
+
# Sort our friends, with the least favorite friend first.
|
192
|
+
sorted_friends = friends.sort_by(&:n_activities)
|
193
|
+
|
194
|
+
output = Hash.new { |h, k| h[k] = [] }
|
195
|
+
|
196
|
+
# First, get not-so-good friends.
|
197
|
+
while sorted_friends.first.n_activities < 2 do
|
198
|
+
output[:distant] << sorted_friends.shift.name
|
199
|
+
end
|
200
|
+
|
201
|
+
output[:moderate] = sorted_friends.slice!(0, sorted_friends.size * 3 / 4).
|
202
|
+
map!(&:name)
|
203
|
+
output[:close] = sorted_friends.map!(&:name)
|
204
|
+
|
205
|
+
output
|
206
|
+
end
|
207
|
+
|
177
208
|
# Sets the n_activities field on each friend.
|
178
209
|
def set_n_activities!
|
179
210
|
# Construct a hash of friend name to frequency of appearance.
|
data/lib/friends/serializable.rb
CHANGED
@@ -12,7 +12,7 @@ module Serializable
|
|
12
12
|
# - deserialization_expectation
|
13
13
|
# a string for what was expected, if the regex does not match
|
14
14
|
def deserialize(str)
|
15
|
-
match = str.match(deserialization_regex)
|
15
|
+
match = str.to_s.match(deserialization_regex)
|
16
16
|
|
17
17
|
unless match
|
18
18
|
raise SerializationError,
|
data/lib/friends/version.rb
CHANGED
data/test/activity_spec.rb
CHANGED
@@ -35,10 +35,12 @@ describe Friends::Activity do
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
describe "when
|
38
|
+
describe "when no description is present" do
|
39
39
|
let(:serialized_str) { "" }
|
40
40
|
|
41
|
-
it
|
41
|
+
it "sets no description in deserialization" do
|
42
|
+
subject.description.must_equal nil
|
43
|
+
end
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
data/test/introvert_spec.rb
CHANGED
@@ -262,6 +262,22 @@ describe Friends::Introvert do
|
|
262
262
|
end
|
263
263
|
end
|
264
264
|
|
265
|
+
describe "#suggest" do
|
266
|
+
subject { introvert.suggest }
|
267
|
+
|
268
|
+
it "returns distant, moderate, and close friends" do
|
269
|
+
introvert.stub(:friends, friends) do
|
270
|
+
introvert.stub(:activities, activities) do
|
271
|
+
subject.must_equal(
|
272
|
+
distant: ["George Washington Carver"],
|
273
|
+
moderate: [],
|
274
|
+
close: ["Betsy Ross"]
|
275
|
+
)
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
265
281
|
describe "#graph" do
|
266
282
|
subject { introvert.graph(name: friend_name) }
|
267
283
|
|
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.
|
4
|
+
version: '0.2'
|
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-
|
11
|
+
date: 2015-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
146
|
version: '0'
|
147
147
|
requirements: []
|
148
148
|
rubyforge_project:
|
149
|
-
rubygems_version: 2.4.
|
149
|
+
rubygems_version: 2.4.8
|
150
150
|
signing_key:
|
151
151
|
specification_version: 4
|
152
152
|
summary: Spend time with the people you care about.
|