Class: Sekki24::Lunisolar::Date

Inherits:
Object
  • Object
show all
Defined in:
lib/sekki24/lunisolar/date.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year:, month:, day:, leap:, gregorian_date:, month_length:) ⇒ Date

Returns a new instance of Date.



8
9
10
11
12
13
14
15
16
# File 'lib/sekki24/lunisolar/date.rb', line 8

def initialize(year:, month:, day:, leap:, gregorian_date:, month_length:)
  @year = year
  @month = month
  @day = day
  @leap = leap
  @gregorian_date = gregorian_date.freeze
  @month_length = month_length
  freeze
end

Instance Attribute Details

#dayObject (readonly)

Returns the value of attribute day.



6
7
8
# File 'lib/sekki24/lunisolar/date.rb', line 6

def day
  @day
end

#gregorian_dateObject (readonly)

Returns the value of attribute gregorian_date.



6
7
8
# File 'lib/sekki24/lunisolar/date.rb', line 6

def gregorian_date
  @gregorian_date
end

#monthObject (readonly)

Returns the value of attribute month.



6
7
8
# File 'lib/sekki24/lunisolar/date.rb', line 6

def month
  @month
end

#month_lengthObject (readonly)

Returns the value of attribute month_length.



6
7
8
# File 'lib/sekki24/lunisolar/date.rb', line 6

def month_length
  @month_length
end

#yearObject (readonly)

Returns the value of attribute year.



6
7
8
# File 'lib/sekki24/lunisolar/date.rb', line 6

def year
  @year
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



31
32
33
34
# File 'lib/sekki24/lunisolar/date.rb', line 31

def ==(other)
  other.is_a?(Date) && year == other.year && month == other.month &&
    day == other.day && leap? == other.leap?
end

#hashObject



37
38
39
# File 'lib/sekki24/lunisolar/date.rb', line 37

def hash
  [self.class, year, month, day, leap?].hash
end

#inspectObject



53
54
55
# File 'lib/sekki24/lunisolar/date.rb', line 53

def inspect
  "#<#{self.class} #{year}#{month_name_ja}#{day}日 (#{gregorian_date.iso8601})>"
end

#leap?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/sekki24/lunisolar/date.rb', line 18

def leap?
  @leap
end

#month_name_jaObject



22
23
24
25
# File 'lib/sekki24/lunisolar/date.rb', line 22

def month_name_ja
  prefix = leap? ? "" : ""
  "#{prefix}#{Month::MONTH_NAMES.fetch(month - 1)}"
end

#to_dateObject



27
28
29
# File 'lib/sekki24/lunisolar/date.rb', line 27

def to_date
  gregorian_date
end

#to_hObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/sekki24/lunisolar/date.rb', line 41

def to_h
  {
    year: year,
    month: month,
    day: day,
    leap: leap?,
    month_name_ja: month_name_ja,
    month_length: month_length,
    gregorian_date: gregorian_date
  }
end