HappyFriday 0.4.1 → 0.5.1

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
  SHA256:
3
- metadata.gz: c9357c7d344a25ec5773cfd40a97641602e5d5e33e10435b00b721ce6f2e777e
4
- data.tar.gz: c0685d10bbfcfa912e6c5621d471060f7cae9efe7eb903943a3c38261c16d6ae
3
+ metadata.gz: e7e2a2da8392cf104f420a5761b804499f3fa5bb531e044f5a3d0cfa3fb9fb28
4
+ data.tar.gz: 19caecefaba952ec58b0955606668de9d6edafd60080792e0e76244808b39a41
5
5
  SHA512:
6
- metadata.gz: 37eb44bf9423090e4399176da90c43be7341b4d5c719b789b316c1d0b3193c98fd8f1fdbc999507468453e4906021b048e053a21a04fa6d6e9534a7c48dfd5af
7
- data.tar.gz: d4e2d3ef75a298d08e4d5e91ad8a99f542988e64095d7302471dc8c58c1b616238382254ba32ade1f85cd5fdf5dd853823c34c7788b45aaebe9619e37f81fcba
6
+ metadata.gz: 6fd4e5698a27346df8827ec58993d0759396b4fa7e1ec3d33a6b2e0d6ceac141c579b3cc068d6394e38deac90e28f33f5611c1b5e521fc53df326f4f90152139
7
+ data.tar.gz: 22452139f2a94c58a69ba6c9a7c45165e2879a80c518dcc13d94adbf791ae7ccb6fe329dbff1f224c1381c8841049913722717908869c238f4526ba2f2b87633
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # HappyFriday
2
2
 
3
3
  This gem is capable of obtaining and determining HappyFriday.
4
+ Extend to Date class.
4
5
 
5
6
  ## Installation
6
7
 
@@ -16,30 +17,25 @@ If bundler is not being used to manage dependencies, install the gem by executin
16
17
 
17
18
  ### HappyFriday decision
18
19
  ```rb
19
- date = Date.new(2022, 5, 3)
20
- HappyFriday.happy_friday?(date)
20
+ Date.new(2022, 5, 3).happy_friday?
21
21
  => false
22
22
 
23
- date = Date.new(2022, 5, 27)
24
- HappyFriday.happy_friday?(date)
23
+ Date.new(2022, 5, 27).happy_friday?
25
24
  => true
26
25
  ```
27
26
 
28
27
  ### Get the next HappyFriday
29
28
  You can get a HappyFriday for that month.
30
29
  ```rb
31
- date = Date.new(2022, 5)
32
- HappyFriday.get_next_happy_friday(date)
30
+ Date.new(2022, 5).get_next_happy_friday
33
31
  => Fri, 27 May 2022
34
32
 
35
33
  # If the last Friday of the month is a holiday, the day before becomes HappyFriday.
36
- date = Date.new(2022, 4)
37
- HappyFriday.get_next_happy_friday(date)
34
+ Date.new(2022, 4).get_next_happy_friday
38
35
  => Thu, 28 Apr 2022
39
36
 
40
37
  # If HappyFriday of that month has passed, get next month.
41
- date = Date.new(2022, 4, 30)
42
- HappyFriday.get_next_happy_friday(date)
38
+ Date.new(2022, 4, 30).get_next_happy_friday
43
39
  => Fri, 27 May 2022
44
40
  ```
45
41
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HappyFriday
4
- VERSION = "0.4.1"
4
+ VERSION = "0.5.1"
5
5
  end
data/lib/HappyFriday.rb CHANGED
@@ -7,12 +7,12 @@ require 'holiday_jp'
7
7
  module HappyFriday
8
8
  class Error < StandardError; end
9
9
 
10
- def self.happy_friday?(target_date)
11
- target_date.strftime("%Y%m%d") == HappyFriday.get_next_happy_friday(target_date).strftime("%Y%m%d")
10
+ def happy_friday?
11
+ self == self.get_next_happy_friday
12
12
  end
13
13
 
14
- def self.get_next_happy_friday(target_date)
15
- last_of_month = Date.new(target_date.year, target_date.month, -1)
14
+ def get_next_happy_friday
15
+ last_of_month = self.end_of_month
16
16
 
17
17
  case last_of_month.wday
18
18
  when 0..4
@@ -27,7 +27,7 @@ module HappyFriday
27
27
 
28
28
  raise 'err' unless last_friday.wday == 5
29
29
 
30
- loop do
30
+ 100.times do
31
31
  if HolidayJp.holiday?(last_friday)
32
32
  last_friday -= 1
33
33
  else
@@ -36,10 +36,8 @@ module HappyFriday
36
36
  end
37
37
 
38
38
  # If HappyFriday of that month has passed, get next month.
39
- # TODO: refactoring
40
- if target_date > last_friday
41
- next_month = last_friday + 1.month
42
- happy_friday = HappyFriday.get_next_happy_friday(Date.new(next_month.year, next_month.month))
39
+ if self > last_friday
40
+ happy_friday = self.next_month.beginning_of_month.get_next_happy_friday
43
41
  else
44
42
  happy_friday = last_friday
45
43
  end
@@ -47,3 +45,7 @@ module HappyFriday
47
45
  happy_friday
48
46
  end
49
47
  end
48
+
49
+ class Date
50
+ include HappyFriday
51
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: HappyFriday
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - holasoynaoki
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-04 00:00:00.000000000 Z
11
+ date: 2022-07-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Determine if today is a HappyFriday.
14
14
  email:
@@ -33,7 +33,7 @@ licenses:
33
33
  metadata:
34
34
  homepage_uri: https://github.com/holasoynaoki/HappyFriday
35
35
  source_code_uri: https://github.com/holasoynaoki/HappyFriday
36
- post_install_message:
36
+ post_install_message:
37
37
  rdoc_options: []
38
38
  require_paths:
39
39
  - lib
@@ -48,8 +48,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  requirements: []
51
- rubygems_version: 3.2.3
52
- signing_key:
51
+ rubygems_version: 3.1.6
52
+ signing_key:
53
53
  specification_version: 4
54
54
  summary: Determine if today is a HappyFriday.
55
55
  test_files: []