HappyFriday 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 293ad98874393ee44a825ad4b7b7f81ca8f899b9403354f772405cd2c6365ae6
4
- data.tar.gz: 020d9e6c5e67a6bfbf7d95ff73d67956bcc627416caeff54f42b3deed3fe732f
3
+ metadata.gz: 3e6b34ad2bc4b4378d098ca54f8fb49f0dc0e3ecd054e9b7d4d6dd88e1999ddd
4
+ data.tar.gz: eec247a173b8213e97dfedc8dc97cff02614068f93086f11fa08a1fa16b7a4ab
5
5
  SHA512:
6
- metadata.gz: ab2ae16f84d5725de1cb4ccb4835cbbb3e3c98183147742b5c91960b40ec7a74ad1a793841492d3652d4b9273e09d0fe009b4f4bc0b8a19e381ceb9bbbef2a88
7
- data.tar.gz: ab3d35e2bbfabdee4653c1835d574e8265e410a7fc463d8d4d3f0389a3f600b6df9a4dddf9a4ccabb846c355cbee3a1b80b434b3e034eb4a3e7cf511ca5bca78
6
+ metadata.gz: 7f2a6d82e73eecb60d00134f3b0d56a9ca8673c60103eb92a37349c95ab4a138a5fb849d1eef1fe99a1b9e0b755a3fade5aede9acb13b7a348e43ad6ce66322d
7
+ data.tar.gz: c42148a21bcbb7b9cb4e8b71e19465d00794746bc11cb75729171820977b28fdc03bae78ebc7f6524128170e12aca826fbb80c3e9a44c1c609ef3bfa54647cb1
data/Gemfile CHANGED
@@ -8,3 +8,5 @@ gemspec
8
8
  gem "rake", "~> 13.0"
9
9
 
10
10
  gem 'holiday_jp', '~> 0.7.0'
11
+
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,10 @@ 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
+ ```rb
18
+ HappyFriday.happyfriday?(Time.now)
19
+ # => true or false returns
20
+ ```
20
21
 
21
22
  ## Development
22
23
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HappyFriday
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
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 == 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
metadata CHANGED
@@ -1,7 +1,7 @@
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.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - holasoynaoki