HappyFriday 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +5 -4
- data/lib/HappyFriday/version.rb +1 -1
- data/lib/HappyFriday.rb +29 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e6b34ad2bc4b4378d098ca54f8fb49f0dc0e3ecd054e9b7d4d6dd88e1999ddd
|
4
|
+
data.tar.gz: eec247a173b8213e97dfedc8dc97cff02614068f93086f11fa08a1fa16b7a4ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f2a6d82e73eecb60d00134f3b0d56a9ca8673c60103eb92a37349c95ab4a138a5fb849d1eef1fe99a1b9e0b755a3fade5aede9acb13b7a348e43ad6ce66322d
|
7
|
+
data.tar.gz: c42148a21bcbb7b9cb4e8b71e19465d00794746bc11cb75729171820977b28fdc03bae78ebc7f6524128170e12aca826fbb80c3e9a44c1c609ef3bfa54647cb1
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# HappyFriday
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Gem that can determine HappyFriday.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -16,7 +14,10 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
16
14
|
|
17
15
|
## Usage
|
18
16
|
|
19
|
-
|
17
|
+
```rb
|
18
|
+
HappyFriday.happyfriday?(Time.now)
|
19
|
+
# => true or false returns
|
20
|
+
```
|
20
21
|
|
21
22
|
## Development
|
22
23
|
|
data/lib/HappyFriday/version.rb
CHANGED
data/lib/HappyFriday.rb
CHANGED
@@ -1,11 +1,38 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "HappyFriday/version"
|
4
|
+
require 'active_support/all'
|
5
|
+
require 'holiday_jp'
|
4
6
|
|
5
7
|
module HappyFriday
|
6
8
|
class Error < StandardError; end
|
7
9
|
|
8
|
-
def self.
|
9
|
-
|
10
|
+
def self.happyfriday?(target_date)
|
11
|
+
target_date == HappyFriday.get_happy_friday(target_date)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.get_happy_friday(date)
|
15
|
+
last_of_month = Date.new(date.year, date.month, -1)
|
16
|
+
|
17
|
+
case last_of_month.wday
|
18
|
+
when 0..4
|
19
|
+
before_friday_days = last_of_month.wday + 2
|
20
|
+
when 5..6
|
21
|
+
before_friday_days = last_of_month.wday - 5
|
22
|
+
else
|
23
|
+
raise 'ERR: Unpredictable day of the week.'
|
24
|
+
end
|
25
|
+
|
26
|
+
last_friday = last_of_month.ago(before_friday_days.days)
|
27
|
+
|
28
|
+
while HolidayJp.holiday?(last_friday)
|
29
|
+
last_friday = last_friday.ago(1.week)
|
30
|
+
end
|
31
|
+
|
32
|
+
if last_friday.month != last_of_month.month
|
33
|
+
raise 'HappyFriday is no month!'
|
34
|
+
end
|
35
|
+
|
36
|
+
last_friday
|
10
37
|
end
|
11
38
|
end
|