Class: Month
Defined Under Namespace
Classes: InvalidMonth, InvalidYear
Constant Summary
Constants included
from Monthstamp
Monthstamp::VERSION
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Monthstamp
#monthstamp, #to_month
Constructor Details
#initialize(month, year) ⇒ Month
Returns a new instance of Month.
17
18
19
20
|
# File 'lib/monthstamp/month.rb', line 17
def initialize month, year
self.month = month
self.year = year
end
|
Instance Attribute Details
#month ⇒ Object
Returns the value of attribute month.
9
10
11
|
# File 'lib/monthstamp/month.rb', line 9
def month
@month
end
|
#year ⇒ Object
Returns the value of attribute year.
9
10
11
|
# File 'lib/monthstamp/month.rb', line 9
def year
@year
end
|
Class Method Details
.at(monthstamp) ⇒ Object
Also known as:
find
23
24
25
26
27
28
|
# File 'lib/monthstamp/month.rb', line 23
def at(monthstamp)
monthstamp = Integer(monthstamp)
year = (monthstamp / 12) + 1970
month = monthstamp % 12 + 1
new(month, year)
end
|
.dump(month) ⇒ Object
36
37
38
|
# File 'lib/monthstamp/month.rb', line 36
def dump(month)
month.monthstamp
end
|
.load(monthstamp) ⇒ Object
40
41
42
|
# File 'lib/monthstamp/month.rb', line 40
def load(monthstamp)
at(monthstamp)
end
|
.now ⇒ Object
44
45
46
|
# File 'lib/monthstamp/month.rb', line 44
def now
at(Date.today.monthstamp)
end
|
.parse(string) ⇒ Object
31
32
33
34
|
# File 'lib/monthstamp/month.rb', line 31
def parse(string)
dt = DateTime.parse(string)
new(dt.month,dt.year)
end
|
Instance Method Details
#<(other) ⇒ Object
162
163
164
|
# File 'lib/monthstamp/month.rb', line 162
def < other
self.monthstamp < other.monthstamp
end
|
#<=>(other) ⇒ Object
59
60
61
|
# File 'lib/monthstamp/month.rb', line 59
def <=> other
monthstamp <=> other.monthstamp
end
|
#==(other) ⇒ Object
Also known as:
eql?
50
51
52
|
# File 'lib/monthstamp/month.rb', line 50
def == other
other && other.month == self.month && other.year == self.year
end
|
#>(other) ⇒ Object
170
171
172
|
# File 'lib/monthstamp/month.rb', line 170
def > other
self.monthstamp > other.monthstamp
end
|
#dates ⇒ Object
158
159
160
|
# File 'lib/monthstamp/month.rb', line 158
def dates
(first_day..last_day)
end
|
#first_day ⇒ Object
150
151
152
|
# File 'lib/monthstamp/month.rb', line 150
def first_day
date_object.beginning_of_month
end
|
#hash ⇒ Object
55
56
57
|
# File 'lib/monthstamp/month.rb', line 55
def hash
monthstamp.hash
end
|
#id ⇒ Object
107
108
109
|
# File 'lib/monthstamp/month.rb', line 107
def id
monthstamp
end
|
#inspect ⇒ Object
91
92
93
|
# File 'lib/monthstamp/month.rb', line 91
def inspect
short_name(false)
end
|
#last_day ⇒ Object
154
155
156
|
# File 'lib/monthstamp/month.rb', line 154
def last_day
date_object.end_of_month
end
|
#last_month ⇒ Object
141
142
143
|
# File 'lib/monthstamp/month.rb', line 141
def last_month
Month.at(monthstamp - 1)
end
|
#last_year ⇒ Object
133
134
135
|
# File 'lib/monthstamp/month.rb', line 133
def last_year
Month.at(monthstamp - 12)
end
|
#month_name ⇒ Object
67
68
69
|
# File 'lib/monthstamp/month.rb', line 67
def month_name
MONTHNAMES[month - 1]
end
|
#name ⇒ Object
63
64
65
|
# File 'lib/monthstamp/month.rb', line 63
def name
month_name + " " + year.to_s
end
|
#next_month ⇒ Object
Also known as:
succ
145
146
147
|
# File 'lib/monthstamp/month.rb', line 145
def next_month
Month.at(monthstamp + 1)
end
|
#next_year ⇒ Object
137
138
139
|
# File 'lib/monthstamp/month.rb', line 137
def next_year
Month.at(monthstamp + 12)
end
|
#number ⇒ Object
99
100
101
|
# File 'lib/monthstamp/month.rb', line 99
def number
@month.to_i
end
|
#number_of_days ⇒ Object
174
175
176
|
# File 'lib/monthstamp/month.rb', line 174
def number_of_days
Time.days_in_month(month, year)
end
|
#short_month_name ⇒ Object
83
84
85
|
# File 'lib/monthstamp/month.rb', line 83
def short_month_name
month_name[0..2]
end
|
#short_name(year_first_month_only = false) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/monthstamp/month.rb', line 71
def short_name year_first_month_only = false
if year_first_month_only
if number == 1
short_month_name + " " + year.to_s
else
short_month_name
end
else
short_month_name + " " + year.to_s
end
end
|
#start_date ⇒ Object
166
167
168
|
# File 'lib/monthstamp/month.rb', line 166
def start_date
Date.new(year,month,1)
end
|
#strftime(*args) ⇒ Object
129
130
131
|
# File 'lib/monthstamp/month.rb', line 129
def strftime *args
date_object.strftime(*args)
end
|
#to_param ⇒ Object
87
88
89
|
# File 'lib/monthstamp/month.rb', line 87
def to_param
id.to_s
end
|
#to_s ⇒ Object
178
179
180
|
# File 'lib/monthstamp/month.rb', line 178
def to_s
"#{month}-#{year}"
end
|