Class: YearMonth
- Inherits:
-
Object
- Object
- YearMonth
- Includes:
- Comparable
- Defined in:
- lib/gitstats/yearmonth.rb
Instance Attribute Summary collapse
-
#month ⇒ Object
readonly
Returns the value of attribute month.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #<=>(b) ⇒ Object
- #eql?(b) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(a, b = nil) ⇒ YearMonth
constructor
A new instance of YearMonth.
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(a, b = nil) ⇒ YearMonth
Returns a new instance of YearMonth.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/gitstats/yearmonth.rb', line 7 def initialize(a, b = nil) if a.is_a? Time @year = a.year @month = a.month elsif b.nil? @year = (a / 100).to_i @month = a % 100 else @year = a.to_i @month = b.to_i end end |
Instance Attribute Details
#month ⇒ Object (readonly)
Returns the value of attribute month.
5 6 7 |
# File 'lib/gitstats/yearmonth.rb', line 5 def month @month end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
4 5 6 |
# File 'lib/gitstats/yearmonth.rb', line 4 def year @year end |
Instance Method Details
#<=>(b) ⇒ Object
20 21 22 |
# File 'lib/gitstats/yearmonth.rb', line 20 def <=>(b) to_i <=> b.to_i end |
#eql?(b) ⇒ Boolean
32 33 34 |
# File 'lib/gitstats/yearmonth.rb', line 32 def eql?(b) to_i == b.to_i end |
#hash ⇒ Object
36 37 38 |
# File 'lib/gitstats/yearmonth.rb', line 36 def hash to_i end |
#to_i ⇒ Object
24 25 26 |
# File 'lib/gitstats/yearmonth.rb', line 24 def to_i @year * 12 + @month - 1 end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/gitstats/yearmonth.rb', line 28 def to_s '%04d-%02d' % [@year, @month] end |