has_streak 0.0.3 → 0.0.4
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 +4 -4
- data/lib/has_streak/streakable.rb +9 -4
- data/lib/has_streak/version.rb +1 -1
- data/spec/streakable_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63ba6abb764f993e38c848030a927c31a005bc2f
|
4
|
+
data.tar.gz: 2613f5a94496a8add316521c1d6379248cc8ec89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a30056b442a2d419d4be6a2a62f93bfc45d90f87915a4ccbe05cdd976b50c21f69c2b3796453370b2f261fe08d2150ed3106fe20800639cfed27f263d61cd07
|
7
|
+
data.tar.gz: 4824d3ec0ad9fcbd0a22a39c4882cda9dcdebfb210a02397b6e800b4b4fb299abacf83ca7c436e1920282d8eebaa707a87c907c0e1a0f1814721a5b63da07060
|
@@ -15,14 +15,19 @@ module HasStreak
|
|
15
15
|
private
|
16
16
|
|
17
17
|
def get_days(association)
|
18
|
-
self.send(association).order(
|
18
|
+
self.send(association).order("created_at DESC").pluck(:created_at).map(&:to_date).uniq
|
19
19
|
end
|
20
20
|
|
21
21
|
def determine_consecutive_days(days)
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
streak = 1
|
23
|
+
days.each_with_index do |day, index|
|
24
|
+
if days[index+1] == day.yesterday
|
25
|
+
streak += 1
|
26
|
+
else
|
27
|
+
break
|
28
|
+
end
|
25
29
|
end
|
30
|
+
streak
|
26
31
|
end
|
27
32
|
|
28
33
|
end
|
data/lib/has_streak/version.rb
CHANGED
data/spec/streakable_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe HasStreak::Streakable do
|
|
7
7
|
it "returns a streak of 3" do
|
8
8
|
user.posts.create(content: "hello", created_at: 2.days.ago)
|
9
9
|
user.posts.create(content: "hello", created_at: 1.day.ago)
|
10
|
-
user.posts.create(content: "hello")
|
10
|
+
user.posts.create(content: "hello", created_at: DateTime.current)
|
11
11
|
|
12
12
|
expect(user.streak(:posts)).to eq(3)
|
13
13
|
end
|
@@ -15,7 +15,7 @@ describe HasStreak::Streakable do
|
|
15
15
|
it "returns streak of one (no streak)" do
|
16
16
|
user.posts.create(content: "hello", created_at: 5.days.ago)
|
17
17
|
user.posts.create(content: "hello", created_at: 2.days.ago)
|
18
|
-
user.posts.create(content: "hello")
|
18
|
+
user.posts.create(content: "hello", created_at: DateTime.current)
|
19
19
|
|
20
20
|
expect(user.streak(:posts)).to eq(1)
|
21
21
|
end
|