Class: Sekki24::Lunisolar::Month

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

Constant Summary collapse

MONTH_NAMES =
%w[正月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十一月 十二月].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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_dateObject (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

#monthObject (readonly)

Returns the value of attribute month.



8
9
10
# File 'lib/sekki24/lunisolar/month.rb', line 8

def month
  @month
end

#new_moon_timeObject (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_longitudesObject (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_dateObject (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

#yearObject (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

#hashObject



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

Returns:

  • (Boolean)


34
35
36
# File 'lib/sekki24/lunisolar/month.rb', line 34

def include?(date)
  (start_date..end_date).cover?(date)
end

#inspectObject



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

Returns:

  • (Boolean)


21
22
23
# File 'lib/sekki24/lunisolar/month.rb', line 21

def leap?
  @leap
end

#lengthObject



25
26
27
# File 'lib/sekki24/lunisolar/month.rb', line 25

def length
  (end_date - start_date).to_i + 1
end

#name_jaObject



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_hObject



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