week_of_month 1.0.1
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.
- data/lib/week_of_month.rb +72 -0
- metadata +78 -0
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext/date/calculations.rb'
|
3
|
+
|
4
|
+
class Date
|
5
|
+
|
6
|
+
WEEK_IN_ENG = {1 => "First", 2 => "Second",
|
7
|
+
3 => "Third", 4 => "Fourth",
|
8
|
+
5 => "Fifth", 6 => "Sixth"}
|
9
|
+
|
10
|
+
# WEEK_IN_FR = {1 => "First", 2 => "Second",
|
11
|
+
# 3 => "Third", 4 => "Quatrième",
|
12
|
+
# 5 => "Cinquième", 6 => "sixième"}
|
13
|
+
#
|
14
|
+
# WEEK_IN_GER = {1 => "First", 2 => "Second",
|
15
|
+
# 3 => "Dritten", 4 => "Vierte",
|
16
|
+
# 5 => "Fünfte", 6 => "Sechste"}
|
17
|
+
|
18
|
+
# WEEK_IN_JAP = {1=>"最初",2 =>"秒",
|
19
|
+
# 3 =>"サード",4=> "第4回",
|
20
|
+
# 5 =>"第五",6=> "シックス"}
|
21
|
+
|
22
|
+
def days_array
|
23
|
+
day = self.beginning_of_month.wday
|
24
|
+
array = []
|
25
|
+
array[day] = 1
|
26
|
+
(2..self.end_of_month.mday).each {|i| array << i }
|
27
|
+
array
|
28
|
+
end
|
29
|
+
|
30
|
+
def week_split
|
31
|
+
days_array.each_slice(7).to_a
|
32
|
+
end
|
33
|
+
|
34
|
+
def week_of_month
|
35
|
+
week_split.each_with_index do |o,i|
|
36
|
+
return (i + 1) if o.include?(self.day)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def first_week?
|
41
|
+
week_split[0].include?((self.day))
|
42
|
+
end
|
43
|
+
|
44
|
+
def second_week?
|
45
|
+
week_split[1].include?((self.day))
|
46
|
+
end
|
47
|
+
|
48
|
+
def last_week?
|
49
|
+
week_split.last.include?((self.day))
|
50
|
+
end
|
51
|
+
|
52
|
+
def total_weeks
|
53
|
+
week_split.size
|
54
|
+
end
|
55
|
+
|
56
|
+
def week_of_month_in_eng
|
57
|
+
WEEK_IN_ENG[week_of_month]
|
58
|
+
end
|
59
|
+
|
60
|
+
#def week_of_month_in_fr
|
61
|
+
# WEEK_IN_FR[week_of_month]
|
62
|
+
#end
|
63
|
+
|
64
|
+
#def week_of_month_in_ger
|
65
|
+
# WEEK_IN_GER[week_of_month]
|
66
|
+
#end
|
67
|
+
|
68
|
+
# def week_of_month_in_jap
|
69
|
+
# WEEK_IN_JAP[week_of_month]
|
70
|
+
# end
|
71
|
+
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: week_of_month
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sachin Singh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activesupport
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Its gives you week_of_month method on date object, that returns week
|
47
|
+
of the month.
|
48
|
+
email: sachin@railsdeveloper.in
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- lib/week_of_month.rb
|
54
|
+
homepage: http://rubygems.org/gems/week_of_month
|
55
|
+
licenses: []
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.8.24
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Week Of Month!
|
78
|
+
test_files: []
|