Sha256: b80abfe7ad30c29c5f59592b321f5cd775cfeddf11c38d650a1cf909eb04f3eb

Contents?: true

Size: 1.78 KB

Versions: 9

Compression:

Stored size: 1.78 KB

Contents

# frozen_string_literal: true

require_relative '../../../../calculation/stella/lunar/abstract_location'

require_relative '../../const/remainder'

require_relative './localization'

# :nodoc:
module Zakuro
  # :nodoc:
  module Daien
    # :nodoc:
    module Lunar
      #
      # Location 入暦
      #
      class Location < Calculation::Lunar::AbstractLocation
        # @return [Cycle::LunarRemainder] 1近点月
        ANOMALISTIC_MONTH = Const::Remainder::Lunar::ANOMALISTIC_MONTH
        # @return [Cycle::LunarRemainder] 弦
        QUARTER = Const::Remainder::Lunar::QUARTER

        #
        # 初期化
        #
        # @param [Cycle::LunarRemainder] lunar_age 天正閏余(大余小余)
        # @param [Integer] western_year 西暦年
        #
        def initialize(lunar_age:, western_year:)
          super(lunar_age: lunar_age, western_year: western_year)
        end

        #
        # 入暦を計算する
        #
        def run
          if calculated
            decrease(limit: ANOMALISTIC_MONTH)
            return
          end

          first
        end

        #
        # 弦の分だけ月地点を進める
        #
        def add_quarter
          remainder.add!(QUARTER)
        end

        private

        #
        # 初回計算
        #
        def first
          @remainder = Localization.first_remainder(
            lunar_age: remainder, western_year: western_year
          )
          decrease(limit: ANOMALISTIC_MONTH)

          @calculated = true
        end

        #
        # 大余小余に合わせて減算する(折り返す)
        #
        # @param [Cycle::LunarRemainder] limit 上限
        #
        def decrease(limit:)
          return if remainder < limit

          remainder.sub!(limit)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
zakuro-0.9.0 lib/zakuro/version/daien/stella/lunar/location.rb
zakuro-0.8.0 lib/zakuro/version/daien/stella/lunar/location.rb
zakuro-0.7.2 lib/zakuro/version/daien/stella/lunar/location.rb
zakuro-0.7.0 lib/zakuro/version/daien/stella/lunar/location.rb
zakuro-0.6.1 lib/zakuro/version/daien/stella/lunar/location.rb
zakuro-0.6.0 lib/zakuro/version/daien/stella/lunar/location.rb
zakuro-0.5.0 lib/zakuro/version/daien/stella/lunar/location.rb
zakuro-0.4.0 lib/zakuro/version/daien/stella/lunar/location.rb
zakuro-0.3.0 lib/zakuro/version/daien/stella/lunar/location.rb