Class: Koyomi::Year

Inherits:
Period show all
Defined in:
lib/koyomi/year.rb

Instance Attribute Summary collapse

Attributes inherited from Period

#range

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year = nil) ⇒ Year

initialize instance.

Parameters:

  • year (Integer) (defaults to: nil)

    optional, default use the year of instance created.



26
27
28
29
30
31
32
# File 'lib/koyomi/year.rb', line 26

def initialize(year = nil)
  super()
  @year   = year||created_at.year
  @first  = Date.new(@year,  1,  1)
  @last   = Date.new(@year, 12, 31)
  @range  = (@first .. @last)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Koyomi::Period

Instance Attribute Details

#firstObject (readonly)

Returns the value of attribute first.



21
22
23
# File 'lib/koyomi/year.rb', line 21

def first
  @first
end

#lastObject (readonly)

Returns the value of attribute last.



21
22
23
# File 'lib/koyomi/year.rb', line 21

def last
  @last
end

#yearObject (readonly)

——————–# instance methods



20
21
22
# File 'lib/koyomi/year.rb', line 20

def year
  @year
end

Class Method Details

.of(date = Date.today) ⇒ Koyomi::Year

create instance from date

Parameters:

  • date (Date) (defaults to: Date.today)

Returns:



13
14
15
# File 'lib/koyomi/year.rb', line 13

def self.of(date = Date.today)
  self.new(date.year)
end

Instance Method Details

#month(month) ⇒ Object



40
41
42
# File 'lib/koyomi/year.rb', line 40

def month(month)
  Koyomi::Month.new(month, year)
end

#uruu?Boolean Also known as: leap?

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
52
# File 'lib/koyomi/year.rb', line 44

def uruu?
  begin
    Date.new(year, 2, 29)
  rescue ArgumentError => e
    false
  else
    true
  end
end