Class: Sekki24::Lunisolar::Month
- Inherits:
-
Object
- Object
- Sekki24::Lunisolar::Month
- Defined in:
- lib/sekki24/lunisolar/month.rb
Constant Summary collapse
- MONTH_NAMES =
%w[正月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十一月 十二月].freeze
Instance Attribute Summary collapse
-
#end_date ⇒ Object
readonly
Returns the value of attribute end_date.
-
#month ⇒ Object
readonly
Returns the value of attribute month.
-
#new_moon_time ⇒ Object
readonly
Returns the value of attribute new_moon_time.
-
#principal_longitudes ⇒ Object
readonly
Returns the value of attribute principal_longitudes.
-
#start_date ⇒ Object
readonly
Returns the value of attribute start_date.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
- #include?(date) ⇒ Boolean
-
#initialize(year:, month:, leap:, start_date:, end_date:, new_moon_time:, principal_longitudes:) ⇒ Month
constructor
A new instance of Month.
- #inspect ⇒ Object
- #leap? ⇒ Boolean
- #length ⇒ Object
- #name_ja ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(year:, month:, leap:, start_date:, end_date:, new_moon_time:, principal_longitudes:) ⇒ Month
Returns a new instance of Month.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/sekki24/lunisolar/month.rb', line 10 def initialize(year:, month:, leap:, start_date:, end_date:, new_moon_time:, principal_longitudes:) @year = year @month = month @leap = leap @start_date = start_date.freeze @end_date = end_date.freeze @new_moon_time = new_moon_time.dup.freeze @principal_longitudes = principal_longitudes.dup.freeze freeze end |
Instance Attribute Details
#end_date ⇒ Object (readonly)
Returns the value of attribute end_date.
8 9 10 |
# File 'lib/sekki24/lunisolar/month.rb', line 8 def end_date @end_date end |
#month ⇒ Object (readonly)
Returns the value of attribute month.
8 9 10 |
# File 'lib/sekki24/lunisolar/month.rb', line 8 def month @month end |
#new_moon_time ⇒ Object (readonly)
Returns the value of attribute new_moon_time.
8 9 10 |
# File 'lib/sekki24/lunisolar/month.rb', line 8 def new_moon_time @new_moon_time end |
#principal_longitudes ⇒ Object (readonly)
Returns the value of attribute principal_longitudes.
8 9 10 |
# File 'lib/sekki24/lunisolar/month.rb', line 8 def principal_longitudes @principal_longitudes end |
#start_date ⇒ Object (readonly)
Returns the value of attribute start_date.
8 9 10 |
# File 'lib/sekki24/lunisolar/month.rb', line 8 def start_date @start_date end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
8 9 10 |
# File 'lib/sekki24/lunisolar/month.rb', line 8 def year @year end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
38 39 40 41 |
# File 'lib/sekki24/lunisolar/month.rb', line 38 def ==(other) other.is_a?(Month) && year == other.year && month == other.month && leap? == other.leap? && start_date == other.start_date end |
#hash ⇒ Object
44 45 46 |
# File 'lib/sekki24/lunisolar/month.rb', line 44 def hash [self.class, year, month, leap?, start_date].hash end |
#include?(date) ⇒ Boolean
34 35 36 |
# File 'lib/sekki24/lunisolar/month.rb', line 34 def include?(date) (start_date..end_date).cover?(date) end |
#inspect ⇒ Object
62 63 64 |
# File 'lib/sekki24/lunisolar/month.rb', line 62 def inspect "#<#{self.class} #{year}年#{name_ja} #{start_date.iso8601}..#{end_date.iso8601}>" end |
#leap? ⇒ Boolean
21 22 23 |
# File 'lib/sekki24/lunisolar/month.rb', line 21 def leap? @leap end |
#length ⇒ Object
25 26 27 |
# File 'lib/sekki24/lunisolar/month.rb', line 25 def length (end_date - start_date).to_i + 1 end |
#name_ja ⇒ Object
29 30 31 32 |
# File 'lib/sekki24/lunisolar/month.rb', line 29 def name_ja prefix = leap? ? "閏" : "" "#{prefix}#{MONTH_NAMES.fetch(month - 1)}" end |
#to_h ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sekki24/lunisolar/month.rb', line 48 def to_h { year: year, month: month, leap: leap?, name_ja: name_ja, start_date: start_date, end_date: end_date, length: length, new_moon_time: new_moon_time, principal_longitudes: principal_longitudes } end |