month.rb 0.10.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.
Files changed (120) hide show
  1. checksums.yaml +7 -0
  2. data/lib/Array/extract_optionsX.rb +14 -0
  3. data/lib/Date/to_month.rb +12 -0
  4. data/lib/Month/Constants.rb +31 -0
  5. data/lib/Month/VERSION.rb +6 -0
  6. data/lib/Month/_comparator.rb +18 -0
  7. data/lib/Month/begin_date.rb +13 -0
  8. data/lib/Month/beginning.rb +13 -0
  9. data/lib/Month/beginning_of_month.rb +13 -0
  10. data/lib/Month/beginning_of_the_month.rb +13 -0
  11. data/lib/Month/cdate.rb +13 -0
  12. data/lib/Month/cdates.rb +13 -0
  13. data/lib/Month/date.rb +13 -0
  14. data/lib/Month/dates.rb +13 -0
  15. data/lib/Month/day.rb +12 -0
  16. data/lib/Month/day_long.rb +12 -0
  17. data/lib/Month/day_short.rb +12 -0
  18. data/lib/Month/day_shortest.rb +12 -0
  19. data/lib/Month/days.rb +13 -0
  20. data/lib/Month/days_in_month.rb +10 -0
  21. data/lib/Month/days_in_the_month.rb +10 -0
  22. data/lib/Month/each_day.rb +13 -0
  23. data/lib/Month/end.rb +13 -0
  24. data/lib/Month/end_date.rb +13 -0
  25. data/lib/Month/end_of_month.rb +13 -0
  26. data/lib/Month/end_of_the_month.rb +13 -0
  27. data/lib/Month/eqlQ.rb +11 -0
  28. data/lib/Month/finish.rb +13 -0
  29. data/lib/Month/finish_date.rb +13 -0
  30. data/lib/Month/finish_of_month.rb +13 -0
  31. data/lib/Month/finish_of_the_month.rb +13 -0
  32. data/lib/Month/hash.rb +12 -0
  33. data/lib/Month/initialize.rb +27 -0
  34. data/lib/Month/last.rb +13 -0
  35. data/lib/Month/last_month.rb +13 -0
  36. data/lib/Month/last_year.rb +13 -0
  37. data/lib/Month/method_missing.rb +21 -0
  38. data/lib/Month/minus.rb +20 -0
  39. data/lib/Month/next.rb +13 -0
  40. data/lib/Month/next_month.rb +13 -0
  41. data/lib/Month/next_year.rb +13 -0
  42. data/lib/Month/plus.rb +16 -0
  43. data/lib/Month/prev.rb +13 -0
  44. data/lib/Month/prev_month.rb +13 -0
  45. data/lib/Month/previous.rb +13 -0
  46. data/lib/Month/previous_month.rb +13 -0
  47. data/lib/Month/prior.rb +12 -0
  48. data/lib/Month/prior_month.rb +13 -0
  49. data/lib/Month/self.begin_date.rb +23 -0
  50. data/lib/Month/self.beginning.rb +12 -0
  51. data/lib/Month/self.beginning_of_month.rb +12 -0
  52. data/lib/Month/self.beginning_of_the_month.rb +12 -0
  53. data/lib/Month/self.cdate.rb +36 -0
  54. data/lib/Month/self.cdates.rb +54 -0
  55. data/lib/Month/self.date.rb +36 -0
  56. data/lib/Month/self.dates.rb +54 -0
  57. data/lib/Month/self.day.rb +20 -0
  58. data/lib/Month/self.day_long.rb +12 -0
  59. data/lib/Month/self.day_short.rb +20 -0
  60. data/lib/Month/self.day_shortest.rb +20 -0
  61. data/lib/Month/self.days.rb +31 -0
  62. data/lib/Month/self.days_in_month.rb +12 -0
  63. data/lib/Month/self.days_in_the_month.rb +12 -0
  64. data/lib/Month/self.end.rb +12 -0
  65. data/lib/Month/self.end_date.rb +24 -0
  66. data/lib/Month/self.end_of_month.rb +12 -0
  67. data/lib/Month/self.end_of_the_month.rb +12 -0
  68. data/lib/Month/self.finish.rb +12 -0
  69. data/lib/Month/self.finish_date.rb +12 -0
  70. data/lib/Month/self.finish_of_month.rb +12 -0
  71. data/lib/Month/self.finish_of_the_month.rb +12 -0
  72. data/lib/Month/self.from_date.rb +14 -0
  73. data/lib/Month/self.last.rb +12 -0
  74. data/lib/Month/self.last_month.rb +12 -0
  75. data/lib/Month/self.last_year.rb +14 -0
  76. data/lib/Month/self.method_missing.rb +20 -0
  77. data/lib/Month/self.next.rb +28 -0
  78. data/lib/Month/self.next_month.rb +12 -0
  79. data/lib/Month/self.next_year.rb +14 -0
  80. data/lib/Month/self.now.rb +12 -0
  81. data/lib/Month/self.of.rb +37 -0
  82. data/lib/Month/self.prev.rb +28 -0
  83. data/lib/Month/self.prev_month.rb +12 -0
  84. data/lib/Month/self.previous.rb +12 -0
  85. data/lib/Month/self.previous_month.rb +12 -0
  86. data/lib/Month/self.prior.rb +12 -0
  87. data/lib/Month/self.prior_month.rb +12 -0
  88. data/lib/Month/self.start.rb +12 -0
  89. data/lib/Month/self.start_date.rb +12 -0
  90. data/lib/Month/self.start_of_month.rb +12 -0
  91. data/lib/Month/self.start_of_the_month.rb +12 -0
  92. data/lib/Month/self.succ.rb +12 -0
  93. data/lib/Month/self.succ_month.rb +12 -0
  94. data/lib/Month/self.successor.rb +12 -0
  95. data/lib/Month/self.successor_month.rb +12 -0
  96. data/lib/Month/self.this.rb +15 -0
  97. data/lib/Month/self.to_i.rb +13 -0
  98. data/lib/Month/self.to_long.rb +20 -0
  99. data/lib/Month/self.to_num.rb +20 -0
  100. data/lib/Month/self.to_number.rb +12 -0
  101. data/lib/Month/self.to_short.rb +20 -0
  102. data/lib/Month/self.today.rb +12 -0
  103. data/lib/Month/self.wday.rb +20 -0
  104. data/lib/Month/start.rb +13 -0
  105. data/lib/Month/start_date.rb +13 -0
  106. data/lib/Month/start_of_month.rb +13 -0
  107. data/lib/Month/start_of_the_month.rb +13 -0
  108. data/lib/Month/succ.rb +13 -0
  109. data/lib/Month/succ_month.rb +13 -0
  110. data/lib/Month/successor.rb +13 -0
  111. data/lib/Month/successor_month.rb +13 -0
  112. data/lib/Month/to_date.rb +13 -0
  113. data/lib/Month/to_i.rb +13 -0
  114. data/lib/Month/to_long.rb +13 -0
  115. data/lib/Month/to_num.rb +13 -0
  116. data/lib/Month/to_number.rb +13 -0
  117. data/lib/Month/to_s.rb +18 -0
  118. data/lib/Month/to_short.rb +13 -0
  119. data/lib/Month.rb +11 -0
  120. metadata +178 -0
@@ -0,0 +1,13 @@
1
+ # Month/previous.rb
2
+ # Month#previous
3
+
4
+ require 'Month/initialize'
5
+ require 'Month/self.previous'
6
+
7
+ class Month
8
+
9
+ def previous
10
+ Month.previous(year, month)
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ # Month/previous_month.rb
2
+ # Month#previous_month
3
+
4
+ require 'Month/initialize'
5
+ require 'Month/self.previous_month'
6
+
7
+ class Month
8
+
9
+ def previous_month
10
+ Month.previous_month(year, month)
11
+ end
12
+
13
+ end
@@ -0,0 +1,12 @@
1
+ # Month/prior.rb
2
+ # Month#prior
3
+
4
+ require 'Month/self.prior'
5
+
6
+ class Month
7
+
8
+ def prior
9
+ Month.prior(year, month)
10
+ end
11
+
12
+ end
@@ -0,0 +1,13 @@
1
+ # Month/prior_month.rb
2
+ # Month#prior_month
3
+
4
+ require 'Month/initialize'
5
+ require 'Month/self.prior_month'
6
+
7
+ class Month
8
+
9
+ def prior_month
10
+ Month.prior_month(year, month)
11
+ end
12
+
13
+ end
@@ -0,0 +1,23 @@
1
+ # Month/self.begin_date.rb
2
+ # Month#self.begin_date
3
+
4
+ require 'date'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ def begin_date(*args)
10
+ year, month = (
11
+ case args.size
12
+ when 0; [Date.today.year, Date.today.month]
13
+ when 1; [Date.today.year, args[0]]
14
+ when 2; [args[0], args[1]]
15
+ else; raise ArgumentError, "too many arguments (#{args.size} for 0, 1, or 2)"
16
+ end
17
+ )
18
+ fail unless (1..12).include?(month)
19
+ Date.new(year, month, 1)
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.beginning.rb
2
+ # Month.beginning
3
+
4
+ require 'Month/self.begin_date'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :beginning, :begin_date
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.beginning_of_month.rb
2
+ # Month#self.beginning_of_month
3
+
4
+ require 'Month/self.beginning'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :beginning_of_month, :beginning
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.beginning_of_month.rb
2
+ # Month#self.beginning_of_month
3
+
4
+ require 'Month/self.beginning'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :beginning_of_the_month, :beginning
10
+
11
+ end
12
+ end
@@ -0,0 +1,36 @@
1
+ # Month/self.cdate.rb
2
+ # Month.cdate
3
+
4
+ require 'date'
5
+ require 'Month/self.cdates'
6
+
7
+ class Month
8
+ class << self
9
+
10
+ def cdate(which_day, day, *args)
11
+ year, month = (
12
+ case args.size
13
+ when 0; [Date.today.year, Date.today.month]
14
+ when 1; [Date.today.year, args[0]]
15
+ when 2; [args[0], args[1]]
16
+ else; raise ArgumentError, "too many arguments (#{args.size + 2} for 2, 3, or 4)"
17
+ end
18
+ )
19
+ fail unless (1..12).include?(month)
20
+ all = self.cdates(year, month, :day => day)
21
+ case which_day.to_s.downcase
22
+ when 'first', '1st', '1'; all[0]
23
+ when 'second', '2nd', '2'; all[1]
24
+ when 'third', '3rd', '3'; all[2]
25
+ when 'fourth', '4th', '4'; all[3]
26
+ when 'fifth', '5th', '5'; all[4]
27
+ when 'last', 'ultimate'; all[all.size - 1]
28
+ when 'second last', '2nd last', 'penultimate'; all[all.size - 2]
29
+ when 'third last', '3rd last'; all[all.size - 3]
30
+ when 'fourth last', '4th last'; all[all.size - 4]
31
+ else; nil
32
+ end
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,54 @@
1
+ # Month/self.cdates.rb
2
+ # Month.cdates
3
+
4
+ require 'Array/extract_optionsX'
5
+ require 'date'
6
+ require 'Month/Constants'
7
+ require 'Month/self.to_num'
8
+ require 'Month/self.days'
9
+
10
+ class Month
11
+ class << self
12
+
13
+ def cdates(*args)
14
+ options = args.extract_options!
15
+ year, month = (
16
+ case args.size
17
+ when 0; [Date.today.year, Date.today.month]
18
+ when 1; [Date.today.year, args[0]]
19
+ when 2; [args[0], args[1]]
20
+ else; raise ArgumentError, "too many arguments (#{args.size} for 0, 1, or 2)"
21
+ end
22
+ )
23
+ list_of_dates = []
24
+ month = self.to_num(month)
25
+ return nil if month.nil?
26
+ unless options[:day].nil?
27
+ if e = ISO_8601_WEEK_DAY_NAMES_LONG.to_a.index(options[:day].to_s.capitalize); weekday_number = e + 1
28
+ elsif e = ISO_8601_WEEK_DAY_NAMES_SHORT.to_a.index(options[:day].to_s.capitalize); weekday_number = e + 1
29
+ elsif e = ISO_8601_WEEK_DAY_NAMES_SHORTEST.to_a.index(options[:day].to_s.capitalize); weekday_number = e + 1
30
+ elsif ISO_8601_WEEK_DAY_NUMBERS_AS_STRINGS.to_a.member?(options[:day]); weekday_number = options[:day].to_i
31
+ elsif ISO_8601_WEEK_DAY_NUMBERS.to_a.member?(options[:day].to_i) && options[:day].class == Integer; weekday_number = options[:day].to_i
32
+ else; return nil
33
+ end
34
+ Date.new(year, month, 1).upto(Date.new(year, month, self.days(year, month))) do |date|
35
+ if options[:date_objects]
36
+ list_of_dates << date if date.cwday == weekday_number
37
+ else
38
+ list_of_dates << date.mday if date.cwday == weekday_number
39
+ end
40
+ end
41
+ else
42
+ Date.new(year, month, 1).upto(Date.new(year, month, self.days(year, month))) do |date|
43
+ if options[:date_objects]
44
+ list_of_dates << date
45
+ else
46
+ list_of_dates << date.mday
47
+ end
48
+ end
49
+ end
50
+ list_of_dates
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,36 @@
1
+ # Month/self.date.rb
2
+ # Month.date
3
+
4
+ require 'date'
5
+ require 'Month/self.dates'
6
+
7
+ class Month
8
+ class << self
9
+
10
+ def date(which_day, day, *args)
11
+ year, month = (
12
+ case args.size
13
+ when 0; [Date.today.year, Date.today.month]
14
+ when 1; [Date.today.year, args[0]]
15
+ when 2; [args[0], args[1]]
16
+ else; raise ArgumentError, "too many arguments (#{args.size} for 2, 3, or 4)"
17
+ end
18
+ )
19
+ fail unless (1..12).include?(month)
20
+ all = self.dates(year, month, :day => day)
21
+ case which_day.to_s.downcase
22
+ when 'first', '1st', '1'; all[0]
23
+ when 'second', '2nd', '2'; all[1]
24
+ when 'third', '3rd', '3'; all[2]
25
+ when 'fourth', '4th', '4'; all[3]
26
+ when 'fifth', '5th', '5'; all[4]
27
+ when 'last', 'ultimate'; all[all.size - 1]
28
+ when 'second last', '2nd last', 'penultimate'; all[all.size - 2]
29
+ when 'third last', '3rd last'; all[all.size - 3]
30
+ when 'fourth last', '4th last'; all[all.size - 4]
31
+ else; nil
32
+ end
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,54 @@
1
+ # Month/self.dates.rb
2
+ # Month.dates
3
+
4
+ require 'Array/extract_optionsX'
5
+ require 'date'
6
+ require 'Month/Constants'
7
+ require 'Month/self.to_num'
8
+ require 'Month/self.days'
9
+
10
+ class Month
11
+ class << self
12
+
13
+ def dates(*args)
14
+ options = args.extract_options!
15
+ year, month = (
16
+ case args.size
17
+ when 0; [Date.today.year, Date.today.month]
18
+ when 1; [Date.today.year, args[0]]
19
+ when 2; [args[0], args[1]]
20
+ else; raise ArgumentError, "too many arguments (#{args.size} for 0, 1, or 2)"
21
+ end
22
+ )
23
+ list_of_dates = []
24
+ month = self.to_num(month)
25
+ return nil if month.nil?
26
+ unless options[:day].nil?
27
+ if e = WEEK_DAY_NAMES_LONG.to_a.index(options[:day].to_s.capitalize); weekday_number = e
28
+ elsif e = WEEK_DAY_NAMES_SHORT.to_a.index(options[:day].to_s.capitalize); weekday_number = e
29
+ elsif e = WEEK_DAY_NAMES_SHORTEST.to_a.index(options[:day].to_s.capitalize); weekday_number = e
30
+ elsif WEEK_DAY_NUMBERS_AS_STRINGS.to_a.member?(options[:day]); weekday_number = options[:day].to_i
31
+ elsif WEEK_DAY_NUMBERS.to_a.member?(options[:day].to_i) && options[:day].class == Integer; weekday_number = options[:day].to_i
32
+ else; return nil
33
+ end
34
+ Date.new(year, month, 1).upto(Date.new(year, month, self.days(year, month))) do |date|
35
+ if options[:date_objects]
36
+ list_of_dates << date if date.wday == weekday_number
37
+ else
38
+ list_of_dates << date.mday if date.wday == weekday_number
39
+ end
40
+ end
41
+ else
42
+ Date.new(year, month, 1).upto(Date.new(year, month, self.days(year, month))) do |date|
43
+ if options[:date_objects]
44
+ list_of_dates << date
45
+ else
46
+ list_of_dates << date.mday
47
+ end
48
+ end
49
+ end
50
+ list_of_dates
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,20 @@
1
+ # Month/self.day.rb
2
+ # Month.day
3
+
4
+ require 'date'
5
+ require 'Month/Constants'
6
+
7
+ class Month
8
+ class << self
9
+
10
+ def day(date, month = Date.today.month, year = Date.today.year)
11
+ date, month, year = date.to_i, self.to_num(month), year.to_i
12
+ if MONTH_DAY_NUMBERS.to_a.member?(date) && MONTH_NUMBERS.to_a.member?(month) && (year.to_s =~ /\d/)
13
+ WEEK_DAY_NAMES_LONG[Date.new(year, month, date).wday]
14
+ else
15
+ nil
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.day_long.rb
2
+ # Month.day_long
3
+
4
+ require 'Month/self.day'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :day_long, :day
10
+
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ # Month/self.day_short.rb
2
+ # Month.day_short
3
+
4
+ require 'date'
5
+ require 'Month/Constants'
6
+
7
+ class Month
8
+ class << self
9
+
10
+ def day_short(date, month = Date.today.month, year = Date.today.year)
11
+ date, month, year = date.to_i, self.to_num(month), year.to_i
12
+ if MONTH_DAY_NUMBERS.to_a.member?(date) && MONTH_NUMBERS.to_a.member?(month) && (year.to_s =~ /\d/)
13
+ WEEK_DAY_NAMES_SHORT[Date.new(year, month, date).wday]
14
+ else
15
+ nil
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # Month/self.day_shortest.rb
2
+ # Month.day_shortest
3
+
4
+ require 'date'
5
+ require 'Month/Constants'
6
+
7
+ class Month
8
+ class << self
9
+
10
+ def day_shortest(date, month = Date.today.month, year = Date.today.year)
11
+ date, month, year = date.to_i, self.to_num(month), year.to_i
12
+ if MONTH_DAY_NUMBERS.to_a.member?(date) && MONTH_NUMBERS.to_a.member?(month) && (year.to_s =~ /\d/)
13
+ WEEK_DAY_NAMES_SHORTEST[Date.new(year, month, date).wday]
14
+ else
15
+ nil
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ # Month/self.days.rb
2
+ # Month.days
3
+
4
+ require 'date'
5
+ require 'Month/Constants'
6
+ require 'Month/to_num'
7
+
8
+ class Month
9
+ class << self
10
+
11
+ def days(*args)
12
+ year, month = (
13
+ case args.size
14
+ when 0; [Date.today.year, Date.today.month]
15
+ when 1; [Date.today.year, args[0]]
16
+ when 2; [args[0], args[1]]
17
+ else; raise ArgumentError, "too many arguments (#{args.size} for 0, 1, or 2)"
18
+ end
19
+ )
20
+ if i = to_num(month)
21
+ case e = MONTH_DAYS[i - 1]
22
+ when Integer; e
23
+ else; e.call(year)
24
+ end
25
+ else
26
+ nil
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.days_in_month.rb
2
+ # Month.days_in_month
3
+
4
+ require 'Month/self.days'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :days_in_month, :days
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.days_in_the_month.rb
2
+ # Month.days_in_the_month
3
+
4
+ require 'Month/self.days'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :days_in_the_month, :days
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.end.rb
2
+ # Month.end
3
+
4
+ require 'Month/self.end_date'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :end, :end_date
10
+
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ # Month/self.end_date.rb
2
+ # Month.end_date
3
+
4
+ require 'date'
5
+ require 'Month/self.days'
6
+
7
+ class Month
8
+ class << self
9
+
10
+ def end_date(*args)
11
+ year, month = (
12
+ case args.size
13
+ when 0; [Date.today.year, Date.today.month]
14
+ when 1; [Date.today.year, args[0]]
15
+ when 2; [args[0], args[1]]
16
+ else; raise ArgumentError, "too many arguments (#{args.size} for 0, 1, or 2)"
17
+ end
18
+ )
19
+ fail unless (1..12).include?(month)
20
+ Date.new(year, month, self.days(year, month))
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.end_of_month.rb
2
+ # Month#self.end_of_month
3
+
4
+ require 'Month/self.end_date'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :end_of_month, :end_date
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.end_of_the_month.rb
2
+ # Month.end_of_the_month
3
+
4
+ require 'Month/self.end_date'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :end_of_the_month, :end_date
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.finish.rb
2
+ # Month.finish
3
+
4
+ require 'Month/self.finish_date'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :finish, :finish_date
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.finish_date.rb
2
+ # Month.finish_date
3
+
4
+ require 'Month/self.end_date'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :finish_date, :end_date
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.finish_of_month.rb
2
+ # Month.finish_of_month
3
+
4
+ require 'Month/self.finish_date'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :finish_of_month, :finish_date
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.finish_of_the_month.rb
2
+ # Month.finish_of_the_month
3
+
4
+ require 'Month/self.finish_date'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :finish_of_the_month, :finish_date
10
+
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # Month/self.from_date.rb
2
+ # Month.from_date
3
+
4
+ # 20140606
5
+
6
+ class Month
7
+ class << self
8
+
9
+ def from_date(date)
10
+ Month.new(date.year, date.month)
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.last.rb
2
+ # Month.last
3
+
4
+ require 'Month/self.last_month'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :last, :last_month
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.last_month.rb
2
+ # Month.last_month
3
+
4
+ require 'Month/self.prev'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :last_month, :prev
10
+
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # Month/self.last_year.rb
2
+ # Month.last_year
3
+
4
+ require 'Month/Constants'
5
+ require 'Month/initialize'
6
+ require 'Month/last_year'
7
+
8
+ class Month
9
+
10
+ def self.last_year(month = Month.new)
11
+ month.last_year
12
+ end
13
+
14
+ end
@@ -0,0 +1,20 @@
1
+ # Month/self.method_missing.rb
2
+ # Month.self
3
+
4
+ require 'Month/self.of'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ def method_missing(method_name, *args, &block)
10
+ if month_object = self.of(method_name, *args, &block)
11
+ month_object
12
+ elsif days = Month.new.send(method_name, *args, &block)
13
+ days
14
+ else
15
+ super(method_name, *args, &block)
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ # Month/self.next.rb
2
+ # Month.next
3
+
4
+ require 'date'
5
+ require 'Month/initialize'
6
+
7
+ class Month
8
+ class << self
9
+
10
+ def next(*args)
11
+ year, month = (
12
+ case args.size
13
+ when 0; [Date.today.year, Date.today.month]
14
+ when 1; [Date.today.year, args[0]]
15
+ when 2; [args[0], args[1]]
16
+ else; raise ArgumentError, "too many arguments (#{args.size} for 0, 1, or 2)"
17
+ end
18
+ )
19
+ fail unless (1..12).include?(month)
20
+ if month == 12
21
+ Month.new(year + 1, 1)
22
+ else
23
+ Month.new(year, month + 1)
24
+ end
25
+ end
26
+
27
+ end
28
+ end