month.rb 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
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,12 @@
1
+ # Month/self.next_month.rb
2
+ # Month.next_month
3
+
4
+ require 'Month/self.next'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :next_month, :next
10
+
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # Month/self.next_year.rb
2
+ # Month.next_year
3
+
4
+ require 'Month/Constants'
5
+ require 'Month/initialize'
6
+ require 'Month/next_year'
7
+
8
+ class Month
9
+
10
+ def self.next_year(month = Month.new)
11
+ month.next_year
12
+ end
13
+
14
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.now.rb
2
+ # Month.now
3
+
4
+ require 'Month/self.today'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :now, :today
10
+
11
+ end
12
+ end
@@ -0,0 +1,37 @@
1
+ # Month/self.of.rb
2
+ # Month.of
3
+
4
+ require 'date'
5
+ require 'Month/initialize'
6
+
7
+ class Month
8
+ class << self
9
+
10
+ def of(*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
+ case month.to_s
20
+ when /^(J|j)an(uary)*$/; new(year, 1)
21
+ when /^(F|f)eb(ruary)*$/; new(year, 2)
22
+ when /^(M|m)ar(ch)*$/; new(year, 3)
23
+ when /^(A|a)pr(il)*$/; new(year, 4)
24
+ when /^(M|m)ay$/; new(year, 5)
25
+ when /^(J|j)un(e)*$/; new(year, 6)
26
+ when /^(J|j)ul(y)*$/; new(year, 7)
27
+ when /^(A|a)ug(ust)*$/; new(year, 8)
28
+ when /^(S|s)ep(tember)*$/; new(year, 9)
29
+ when /^(O|o)ct(ober)*$/; new(year, 10)
30
+ when /^(N|n)ov(ember)*$/; new(year, 11)
31
+ when /^(D|d)ec(ember)*$/; new(year, 12)
32
+ else; nil
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,28 @@
1
+ # Month/self.prev.rb
2
+ # Month.prev
3
+
4
+ require 'date'
5
+ require 'Month/initialize'
6
+
7
+ class Month
8
+ class << self
9
+
10
+ def prev(*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 == 1
21
+ Month.new(year - 1, 12)
22
+ else
23
+ Month.new(year, month - 1)
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.prev_month.rb
2
+ # Month.prev_month
3
+
4
+ require 'Month/self.prev'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :prev_month, :prev
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.previous.rb
2
+ # Month.previous
3
+
4
+ require 'Month/self.prev'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :previous, :prev
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.previous_month.rb
2
+ # Month.previous_month
3
+
4
+ require 'Month/self.previous_month'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :previous_month, :prev
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.prior.rb
2
+ # Month.prior
3
+
4
+ require 'Month/self.prev'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :prior, :prev
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.prior_month.rb
2
+ # Month.prior_month
3
+
4
+ require 'Month/self.prev'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :prior_month, :prev
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.start.rb
2
+ # Month.start
3
+
4
+ require 'Month/self.start_date'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :start, :start_date
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.start_date.rb
2
+ # Month.start_date
3
+
4
+ require 'Month/self.begin_date'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :start_date, :begin_date
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.start_of_month.rb
2
+ # Month.start_of_month
3
+
4
+ require 'Month/self.start_date'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :start_of_month, :start_date
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.start_of_the_month.rb
2
+ # Month.start_of_the_month
3
+
4
+ require 'Month/self.start_date'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :start_of_the_month, :start_date
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.succ.rb
2
+ # Month.succ
3
+
4
+ require 'Month/self.next'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :succ, :next
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.succ_month.rb
2
+ # Month.succ_month
3
+
4
+ require 'Month/self.next'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :succ_month, :next
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.successor.rb
2
+ # Month.successor
3
+
4
+ require 'Month/self.next'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :successor, :next
10
+
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.successor_month.rb
2
+ # Month.successor_month
3
+
4
+ require 'Month/self.next'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :successor_month, :next
10
+
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ # Month/self.this.rb
2
+ # Month.this
3
+
4
+ require 'date'
5
+ require 'Month/initialize'
6
+
7
+ class Month
8
+ class << self
9
+
10
+ def this
11
+ Month.new(Date.today.month)
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ # Month/self.to_i.rb
2
+ # Month.to_i
3
+
4
+ require 'date'
5
+ require 'Month/Constants'
6
+
7
+ class Month
8
+ class << self
9
+
10
+ alias_method :to_i, :to_num
11
+
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ # Month/self.to_long.rb
2
+ # Month.to_long
3
+
4
+ require 'date'
5
+ require 'Month/Constants'
6
+
7
+ class Month
8
+ class << self
9
+
10
+ def to_long(month = Date.today.month)
11
+ if i = MONTH_NAMES_SHORT.index(month.to_s.capitalize); MONTH_NAMES_LONG[i]
12
+ elsif i = MONTH_NAMES_LONG.index(month.to_s.capitalize); MONTH_NAMES_LONG[i]
13
+ elsif i = MONTH_NUMBERS.to_a.index(month); MONTH_NAMES_LONG[i]
14
+ elsif i = MONTH_NUMBERS_AS_STRINGS.to_a.index(month.to_s); MONTH_NAMES_LONG[i]
15
+ else; nil
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # Month/self.to_num.rb
2
+ # Month.to_num
3
+
4
+ require 'date'
5
+ require 'Month/Constants'
6
+
7
+ class Month
8
+ class << self
9
+
10
+ def to_num(month = Date.today.month)
11
+ if i = MONTH_NAMES_SHORT.index(month.to_s.capitalize); i + 1
12
+ elsif i = MONTH_NAMES_LONG.index(month.to_s.capitalize); i + 1
13
+ elsif i = MONTH_NUMBERS.to_a.index(month); i + 1
14
+ elsif i = MONTH_NUMBERS_AS_STRINGS.to_a.index(month.to_s); i + 1
15
+ else; nil
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.to_number.rb
2
+ # Month.to_number
3
+
4
+ require 'Month/self.to_num'
5
+
6
+ class Month
7
+ class << self
8
+
9
+ alias_method :to_number, :to_num
10
+
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ # Month/self.to_short.rb
2
+ # Month.to_short
3
+
4
+ require 'date'
5
+ require 'Month/Constants'
6
+
7
+ class Month
8
+ class << self
9
+
10
+ def to_short(month = Date.today.month)
11
+ if i = MONTH_NAMES_SHORT.index(month.to_s.capitalize); MONTH_NAMES_SHORT[i]
12
+ elsif i = MONTH_NAMES_LONG.index(month.to_s.capitalize); MONTH_NAMES_SHORT[i]
13
+ elsif i = MONTH_NUMBERS.to_a.index(month); MONTH_NAMES_SHORT[i]
14
+ elsif i = MONTH_NUMBERS_AS_STRINGS.to_a.index(month.to_s); MONTH_NAMES_SHORT[i]
15
+ else; nil
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ # Month/self.today.rb
2
+ # Month.today
3
+
4
+ require 'Month/initialize'
5
+
6
+ class Month
7
+
8
+ def self.today
9
+ new
10
+ end
11
+
12
+ end
@@ -0,0 +1,20 @@
1
+ # Month/self.wday.rb
2
+ # Month.wday
3
+
4
+ require 'date'
5
+ require 'Month/Constants'
6
+
7
+ class Month
8
+ class << self
9
+
10
+ def wday(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
+ Date.new(year, month, date).wday
14
+ else
15
+ nil
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ # Month/start.rb
2
+ # Month#start
3
+
4
+ require 'Month/initialize'
5
+ require 'Month/self.start'
6
+
7
+ class Month
8
+
9
+ def start
10
+ Month.start(year, month)
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ # Month/start_date.rb
2
+ # Month#start_date
3
+
4
+ require 'Month/initialize'
5
+ require 'Month/self.start_date'
6
+
7
+ class Month
8
+
9
+ def start_date
10
+ Month.start_date(year, month)
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ # Month/start_of_month.rb
2
+ # Month#start_of_month
3
+
4
+ require 'Month/initialize'
5
+ require 'Month/self.start_of_month'
6
+
7
+ class Month
8
+
9
+ def start_of_month
10
+ Month.start_of_month(year, month)
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ # Month/start_of_the_month.rb
2
+ # Month#start_of_the_month
3
+
4
+ require 'Month/initialize'
5
+ require 'Month/self.start_of_the_month'
6
+
7
+ class Month
8
+
9
+ def start_of_the_month
10
+ Month.start_of_the_month(year, month)
11
+ end
12
+
13
+ end
data/lib/Month/succ.rb ADDED
@@ -0,0 +1,13 @@
1
+ # Month/succ.rb
2
+ # Month#succ
3
+
4
+ require 'Month/initialize'
5
+ require 'Month/self.succ'
6
+
7
+ class Month
8
+
9
+ def succ
10
+ Month.succ(year, month)
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ # Month/succ_month.rb
2
+ # Month#succ_month
3
+
4
+ require 'Month/initialize'
5
+ require 'Month/self.succ_month'
6
+
7
+ class Month
8
+
9
+ def succ_month
10
+ Month.succ_month(year, month)
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ # Month/successor.rb
2
+ # Month#successor
3
+
4
+ require 'Month/initialize'
5
+ require 'Month/self.successor'
6
+
7
+ class Month
8
+
9
+ def successor
10
+ Month.successor(year, month)
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ # Month/successor_month.rb
2
+ # Month#successor_month
3
+
4
+ require 'Month/initialize'
5
+ require 'Month/self.successor_month'
6
+
7
+ class Month
8
+
9
+ def successor_month
10
+ Month.successor_month(year, month)
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ # Month/to_date.rb
2
+ # Month#to_date
3
+
4
+ require 'date'
5
+ require 'Month/initialize'
6
+
7
+ class Month
8
+
9
+ def to_date
10
+ Date.new(year, month, 1)
11
+ end
12
+
13
+ end
data/lib/Month/to_i.rb ADDED
@@ -0,0 +1,13 @@
1
+ # Month/to_i.rb
2
+ # Month#to_i
3
+
4
+ require 'Month/initialize'
5
+ require 'Month/self.to_i'
6
+
7
+ class Month
8
+
9
+ def to_i
10
+ Month.to_i(month)
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ # Month/to_long.rb
2
+ # Month#to_long
3
+
4
+ require 'Month/initialize'
5
+ require 'Month/self.to_long'
6
+
7
+ class Month
8
+
9
+ def to_long
10
+ Month.to_long(month)
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ # Month/to_num.rb
2
+ # Month#to_num
3
+
4
+ require 'Month/initialize'
5
+ require 'Month/self.to_num'
6
+
7
+ class Month
8
+
9
+ def to_num
10
+ Month.to_num(month)
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ # Month/to_number.rb
2
+ # Month#to_number
3
+
4
+ require 'Month/initialize'
5
+ require 'Month/self.to_number'
6
+
7
+ class Month
8
+
9
+ def to_number
10
+ Month.to_number(month)
11
+ end
12
+
13
+ end
data/lib/Month/to_s.rb ADDED
@@ -0,0 +1,18 @@
1
+ # Month/to_s.rb
2
+ # Month#to_s
3
+
4
+ require 'Month/initialize'
5
+ require 'Month/to_long'
6
+ require 'Month/to_short'
7
+
8
+ class Month
9
+
10
+ def to_s(month_name_length = :long)
11
+ case month_name_length.to_sym
12
+ when :long; "#{to_long} #{year}"
13
+ when :short, 'short'; "#{to_short} #{year}"
14
+ when :iso, :iso_8601; "#{year}-" + "%02d" % month
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,13 @@
1
+ # Month/to_short.rb
2
+ # Month#to_short
3
+
4
+ require 'Month/initialize'
5
+ require 'Month/self.to_short'
6
+
7
+ class Month
8
+
9
+ def to_short
10
+ Month.to_short(month)
11
+ end
12
+
13
+ end
data/lib/Month.rb ADDED
@@ -0,0 +1,11 @@
1
+ # Month.rb
2
+ # Month
3
+
4
+ lib_dir = File.expand_path(File.join(File.dirname(__FILE__)))
5
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
6
+
7
+ require 'Date/to_month'
8
+ require 'Month/Constants'
9
+
10
+ lib_files = Dir[File.join(lib_dir, 'Month', '*.rb')].reject{|file| file =~ /Constants/ }
11
+ lib_files.each{|lib_file| load lib_file}