HappyFriday 0.1.0 → 0.3.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: 293ad98874393ee44a825ad4b7b7f81ca8f899b9403354f772405cd2c6365ae6
4
- data.tar.gz: 020d9e6c5e67a6bfbf7d95ff73d67956bcc627416caeff54f42b3deed3fe732f
3
+ metadata.gz: dc61748501928c69e0c18053c2ec7bba02c344bf19a545f91e56f701877b4202
4
+ data.tar.gz: ec5251820ad1d7c24dfae6fab231e0e0ab9ba1bcb760b697eb0aab75c8530ed4
5
5
  SHA512:
6
- metadata.gz: ab2ae16f84d5725de1cb4ccb4835cbbb3e3c98183147742b5c91960b40ec7a74ad1a793841492d3652d4b9273e09d0fe009b4f4bc0b8a19e381ceb9bbbef2a88
7
- data.tar.gz: ab3d35e2bbfabdee4653c1835d574e8265e410a7fc463d8d4d3f0389a3f600b6df9a4dddf9a4ccabb846c355cbee3a1b80b434b3e034eb4a3e7cf511ca5bca78
6
+ metadata.gz: aca0d24fc307b04be91c461f46a99cc5dfbb05edaac1074adeb05eecdbdf4c837fff6491c30fc28490bf06a0790cccc3d1e54f6af8ad9f03286fe5f3e44de5fe
7
+ data.tar.gz: a1041d067961bbccda61f0669b824959a2291449e1828f46202a0a254b1483c3466d4dee61f0a3199ea58109686e9f1ff295efa0895e0ff316b5503c2ff1f3ca
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile CHANGED
@@ -6,5 +6,7 @@ source "https://rubygems.org"
6
6
  gemspec
7
7
 
8
8
  gem "rake", "~> 13.0"
9
+ gem 'rspec'
9
10
 
10
11
  gem 'holiday_jp', '~> 0.7.0'
12
+ gem 'activesupport'
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # HappyFriday
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/HappyFriday`. To experiment with that code, run `bin/console` for an interactive prompt.
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,22 @@ If bundler is not being used to manage dependencies, install the gem by executin
16
14
 
17
15
  ## Usage
18
16
 
19
- TODO: Write usage instructions here
17
+ ### HappyFriday decision
18
+ true or false returns.
19
+ ```rb
20
+ date = Date.new(2022, 5, 3)
21
+ HappyFriday.happyfriday?(date) # false
22
+
23
+ date = Date.new(2022, 5, 27)
24
+ HappyFriday.happyfriday?(date) # true
25
+ ```
26
+
27
+ ### Getting HappyFriday
28
+ You can get a HappyFriday for that month.
29
+ ```rb
30
+ date = Date.new(2022, 5, 1)
31
+ HappyFriday.get_happy_friday(date) # 2022-05-27 00:00:00 +0900
32
+ ```
20
33
 
21
34
  ## Development
22
35
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HappyFriday
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.1"
5
5
  end
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.test
9
- "test"
10
+ def self.happyfriday?(target_date)
11
+ target_date.strftime("%Y%m%d") == HappyFriday.get_happy_friday(target_date).strftime("%Y%m%d")
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 'Unpredictable day of the week.'
24
+ end
25
+
26
+ last_friday = last_of_month.ago(before_friday_days.days)
27
+
28
+ raise 'err' unless last_friday.wday == 5
29
+
30
+ # Doesn't work
31
+ # while HolidayJp.holiday?(last_friday)
32
+ # last_friday = last_friday.ago(1.week)
33
+ # end
34
+ # return false if last_friday.month != last_of_month.month
35
+
36
+ last_friday
10
37
  end
11
38
  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.1.0
4
+ version: 0.3.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-05-30 00:00:00.000000000 Z
11
+ date: 2022-05-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Determine if today is a HappyFriday.
14
14
  email:
@@ -17,6 +17,7 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".rspec"
20
21
  - CHANGELOG.md
21
22
  - CODE_OF_CONDUCT.md
22
23
  - Gemfile
@@ -32,7 +33,7 @@ licenses:
32
33
  metadata:
33
34
  homepage_uri: https://github.com/holasoynaoki/HappyFriday
34
35
  source_code_uri: https://github.com/holasoynaoki/HappyFriday
35
- post_install_message:
36
+ post_install_message:
36
37
  rdoc_options: []
37
38
  require_paths:
38
39
  - lib
@@ -47,8 +48,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
48
  - !ruby/object:Gem::Version
48
49
  version: '0'
49
50
  requirements: []
50
- rubygems_version: 3.3.9
51
- signing_key:
51
+ rubygems_version: 3.2.15
52
+ signing_key:
52
53
  specification_version: 4
53
54
  summary: Determine if today is a HappyFriday.
54
55
  test_files: []