Class: Sekki24::Lunisolar::Date
- Inherits:
-
Object
- Object
- Sekki24::Lunisolar::Date
- Defined in:
- lib/sekki24/lunisolar/date.rb
Instance Attribute Summary collapse
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#gregorian_date ⇒ Object
readonly
Returns the value of attribute gregorian_date.
-
#month ⇒ Object
readonly
Returns the value of attribute month.
-
#month_length ⇒ Object
readonly
Returns the value of attribute month_length.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(year:, month:, day:, leap:, gregorian_date:, month_length:) ⇒ Date
constructor
A new instance of Date.
- #inspect ⇒ Object
- #leap? ⇒ Boolean
- #month_name_ja ⇒ Object
- #to_date ⇒ Object
- #to_h ⇒ Object
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
#day ⇒ Object (readonly)
Returns the value of attribute day.
6 7 8 |
# File 'lib/sekki24/lunisolar/date.rb', line 6 def day @day end |
#gregorian_date ⇒ Object (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 |
#month ⇒ Object (readonly)
Returns the value of attribute month.
6 7 8 |
# File 'lib/sekki24/lunisolar/date.rb', line 6 def month @month end |
#month_length ⇒ Object (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 |
#year ⇒ Object (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 |
#hash ⇒ Object
37 38 39 |
# File 'lib/sekki24/lunisolar/date.rb', line 37 def hash [self.class, year, month, day, leap?].hash end |
#inspect ⇒ Object
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
18 19 20 |
# File 'lib/sekki24/lunisolar/date.rb', line 18 def leap? @leap end |
#month_name_ja ⇒ Object
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_date ⇒ Object
27 28 29 |
# File 'lib/sekki24/lunisolar/date.rb', line 27 def to_date gregorian_date end |
#to_h ⇒ Object
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 |