nth_week_with_rules 1.0.0 → 1.0.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
- SHA1:
3
- metadata.gz: 374127cc6058286b380bc250993f13a62e968852
4
- data.tar.gz: ea996afd125f19092f13480519263ae6c3c49a68
2
+ SHA256:
3
+ metadata.gz: 37a3231942f64048c3a5a827dd1b89e9f1ca001df80816985c791fa95c9df796
4
+ data.tar.gz: 387b4eb799ec0bf11450c0b74af12d68ffcb6b3ee802250f41b4fb34a4d16665
5
5
  SHA512:
6
- metadata.gz: 6459ce06b3e9a54d00e7cc44a923e8255e4424e18abe6ca2e49fb7cd07a330aa66208adbc0a7e653c568dc73a010f5b072821c0a7b0fdb70ff6db9fd4e98a7aa
7
- data.tar.gz: 7383aaa90d1455f441f24a7d080c557530b66f6c4ffdc5fac2d5e513f878868b27082390447a4939fa9368849ed68ab37b2fb4a4f2243695cd3815652ce76cd0
6
+ metadata.gz: 5f35db9dcb49e3d29a2fc81f2efb714458c965ec419f543b2c966e8af6d843af110e2c941565a76503988c0eca30f29c3436f95e614ec0dc573dc41902a6e709
7
+ data.tar.gz: 940b8b5e92c290d365de81f1d7eba9ace2fc9f363de8414636ee96824a8861d075ed8cb6b6a8b398a383c184f4a75f465d84de4a3fda34b7f474717a0ecefd53
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 ka
3
+ Copyright (c) 2016-2023 ka
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module NthWeekWithRules
2
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
3
5
  end
@@ -1,33 +1,32 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "nth_week_with_rules/version"
2
4
 
5
+ # Additional features module to be included in `Date` class
3
6
  module NthWeekWithRules
4
- # @param [Fixnum] first_wday 0, 1, 2, 3, 4, 5 or 6 (default is 0)
7
+ class InvalidMonthSelectError < StandardError; end
8
+
9
+ # @param [Integer] first_wday 0, 1, 2, 3, 4, 5 or 6 (default is 0)
5
10
  # @param [Symbol] month_select :normal, :before, :after, :many (default is :normal)
6
- # @param [Fixnum] base 0 or 1 (default is 1)
7
- # @return [Fixnum] An integer from 1 to 6 (from 0 to 5 if **base** is 0)
11
+ # @param [Integer] base 0 or 1 (default is 1)
12
+ # @return [Integer] An integer from 1 to 6 (from 0 to 5 if **base** is 0)
8
13
  def nth_week(first_wday: 0, month_select: :normal, base: 1)
9
- start_date = first_date_of_week(first_wday: first_wday)
10
- end_date = start_date + 7
14
+ start_date = first_date_of_week(first_wday: first_wday)
15
+ end_date = start_date + 7
11
16
 
12
17
  week = (start_date.day + 5) / 7
13
18
  case month_select
14
19
  when :normal
15
- if start_date.month != end_date.month && self.month == end_date.month
16
- week = 0
17
- end
20
+ week = 0 if start_date.month != end_date.month && month == end_date.month
18
21
  when :before
19
22
  # Do nothing
20
23
  when :after
21
- if start_date.month != end_date.month
22
- week = 0
23
- end
24
+ week = 0 if start_date.month != end_date.month
24
25
  when :many
25
26
  middle_date = start_date + 3
26
- if start_date.month != end_date.month && middle_date.month == end_date.month
27
- week = 0
28
- end
27
+ week = 0 if start_date.month != end_date.month && middle_date.month == end_date.month
29
28
  else
30
- # Error
29
+ raise InvalidMonthSelectError
31
30
  end
32
31
  base + week
33
32
  end
@@ -35,7 +34,7 @@ module NthWeekWithRules
35
34
  # @param [Fixnum] first_wday 0, 1, 2, 3, 4, 5 or 6 (default is 0)
36
35
  # @return [Date] first date of the week of this instance's date
37
36
  def first_date_of_week(first_wday: 0)
38
- self - ((self.wday - first_wday) % 7)
37
+ self - ((wday - first_wday) % 7)
39
38
  end
40
39
  end
41
40
 
metadata CHANGED
@@ -1,99 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nth_week_with_rules
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ka
8
- autorequire:
9
- bindir: exe
8
+ autorequire:
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-03 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.11'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.11'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '11.1'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '11.1'
41
- - !ruby/object:Gem::Dependency
42
- name: test-unit
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.1'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.1'
55
- - !ruby/object:Gem::Dependency
56
- name: test-unit-notify
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.0'
69
- - !ruby/object:Gem::Dependency
70
- name: guard
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '2.13'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '2.13'
83
- - !ruby/object:Gem::Dependency
84
- name: guard-minitest
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '2.4'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '2.4'
11
+ date: 2023-06-27 00:00:00.000000000 Z
12
+ dependencies: []
97
13
  description: Calculate n-th week of the date with some rules
98
14
  email:
99
15
  - ka.kaosf@gmail.com
@@ -101,22 +17,16 @@ executables: []
101
17
  extensions: []
102
18
  extra_rdoc_files: []
103
19
  files:
104
- - ".gitignore"
105
- - Gemfile
106
- - Guardfile
107
20
  - LICENSE.txt
108
- - README.md
109
- - Rakefile
110
- - bin/console
111
- - bin/setup
112
21
  - lib/nth_week_with_rules.rb
113
22
  - lib/nth_week_with_rules/version.rb
114
- - nth_week_with_rules.gemspec
115
23
  homepage: https://github.com/kaosf/nth_week_with_rules
116
24
  licenses:
117
25
  - MIT
118
- metadata: {}
119
- post_install_message:
26
+ metadata:
27
+ homepage_uri: https://github.com/kaosf/nth_week_with_rules
28
+ source_code_uri: https://github.com/kaosf/nth_week_with_rules
29
+ post_install_message:
120
30
  rdoc_options: []
121
31
  require_paths:
122
32
  - lib
@@ -124,17 +34,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
34
  requirements:
125
35
  - - ">="
126
36
  - !ruby/object:Gem::Version
127
- version: '0'
37
+ version: 2.6.0
128
38
  required_rubygems_version: !ruby/object:Gem::Requirement
129
39
  requirements:
130
40
  - - ">="
131
41
  - !ruby/object:Gem::Version
132
42
  version: '0'
133
43
  requirements: []
134
- rubyforge_project:
135
- rubygems_version: 2.5.1
136
- signing_key:
44
+ rubygems_version: 3.4.10
45
+ signing_key:
137
46
  specification_version: 4
138
47
  summary: Calculate n-th week of the date with some rules
139
48
  test_files: []
140
- has_rdoc:
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in nth_week_with_rules.gemspec
4
- gemspec
data/Guardfile DELETED
@@ -1,7 +0,0 @@
1
- # vim: ft=ruby
2
-
3
- guard :minitest do
4
- watch(%r{^test/(.*)\/?test_(.*)\.rb$})
5
- watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
6
- watch(%r{^test/test_helper\.rb$}) { 'test' }
7
- end
data/README.md DELETED
@@ -1,118 +0,0 @@
1
- # NthWeekWithRules
2
-
3
- Calculate n-th week of the date with some rules.
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'nth_week_with_rules'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install nth_week_with_rules
20
-
21
- ## Usage
22
-
23
- ```ruby
24
- require 'nth_week_with_rules'
25
-
26
- date = Date.new(2016, 4, 1)
27
-
28
- date.nth_week #=> 1 (means 1st week of 2016-04)
29
-
30
- date.nth_week(month_select: before) #=> 5 (means 5th week of 2016-03)
31
- # :before option makes the method to take a before month
32
- # if the week is over 2 months.
33
-
34
- date = Date.new(2016, 3, 31)
35
-
36
- date.nth_week(month_select: :after) #=> 1 (means 1st week of 2016-04)
37
- # :after option makes the method to take a after month
38
- # if the week is over 2 months.
39
-
40
- date = Date.new(2016, 9, 1)
41
-
42
- date.nth_week(month_select: :many) #=> 5 (means 5th week of 2016-08)
43
- # :many option makes the method to take a month which has many days.
44
- # 2016-08-28, 2016-08-29, 2016-08-30, 2016-08-31: 4 days
45
- # 2016-09-01, 2016-09-02, 2016-09-03: 3 days
46
-
47
- date = Date.new(2016, 4, 30)
48
-
49
- date.nth_week(first_wday: 6) #=> 6 (means 6th week of 2016-04)
50
- # Do all calculations on the calendar that Saturday is the first wday.
51
- # If the first wday of a calendar is Saturday, 2016-04 becomes below:
52
- #
53
- # Sa Su Mo Tu We Th Fr
54
- # 1
55
- # 2 3 4 5 6 7 8
56
- # 9 10 11 12 13 14 15
57
- # 16 17 18 19 20 21 22
58
- # 23 24 25 26 27 28 29
59
- # 30
60
- #
61
- # So 2016-04-01 is the 6th week of 2016-04.
62
-
63
- date = Date.new(2016, 4, 1)
64
- date.nth_week #=> 1
65
- date.nth_week(base: 0) #=> 0
66
- # You can get 0 base indices. The default base is 1.
67
- ```
68
-
69
- Of cource you can use a complex rule.
70
-
71
- ```ruby
72
- date = Date.new(2016, 4, 1)
73
- date.nth_week(first_wday: 3, month_select: :before, base: 0) #=> 5
74
- ```
75
-
76
- ...Is it really correct? Yes!
77
-
78
- ```
79
- # Start from Wednesday (wday 3)
80
- #
81
- # March 2016
82
- # We Th Fr Sa Su Mo Tu
83
- # 1 0th (start from 0th because of base 0 specification)
84
- # 2 3 4 5 6 7 8 1st
85
- # 9 10 11 12 13 14 15 2nd
86
- # 16 17 18 19 20 21 22 3rd
87
- # 23 24 25 26 27 28 29 4th
88
- # 30 31 5th
89
- #
90
- # April 2016
91
- # We Th Fr Sa Su Mo Tu
92
- # 1 2 3 4 5 0th (2016-04-01 is here! And select_month is :before)
93
- # 6 7 8 9 10 11 12 1st
94
- # 13 14 15 16 17 18 19 ...
95
- # 20 21 22 23 24 25 26
96
- # 27 28 29 30
97
- ```
98
-
99
- So, 2016-04-01 is the 5th week of 2016-03.
100
-
101
- ## Development
102
-
103
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
104
-
105
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
106
-
107
- Run `bundle exec guard` for the automatic testing.
108
-
109
- ## Contributing
110
-
111
- Bug reports and pull requests are welcome on GitHub at https://github.com/kaosf/nth_week_with_rules.
112
-
113
-
114
- ## License
115
-
116
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
117
-
118
- Copyright (C) 2016 ka
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new do |t|
5
- t.libs << "test"
6
- t.test_files = Dir["test/**/test_*.rb"]
7
- t.verbose = true
8
- end
9
-
10
- task default: :test
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "nth_week_with_rules"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,28 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'nth_week_with_rules/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "nth_week_with_rules"
8
- spec.version = NthWeekWithRules::VERSION
9
- spec.authors = ["ka"]
10
- spec.email = ["ka.kaosf@gmail.com"]
11
-
12
- spec.summary = %q{Calculate n-th week of the date with some rules}
13
- spec.description = %q{Calculate n-th week of the date with some rules}
14
- spec.homepage = "https://github.com/kaosf/nth_week_with_rules"
15
- spec.license = "MIT"
16
-
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
21
-
22
- spec.add_development_dependency "bundler", "~> 1.11"
23
- spec.add_development_dependency "rake", "~> 11.1"
24
- spec.add_development_dependency "test-unit", "~> 3.1"
25
- spec.add_development_dependency "test-unit-notify", "~> 1.0"
26
- spec.add_development_dependency "guard", "~> 2.13"
27
- spec.add_development_dependency "guard-minitest", "~> 2.4"
28
- end