Sha256: 9777db7cded804737037ceb9c9ceae46bf1c6391abc94759ea843251844106aa

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

require_relative '../../monthly/month'

# :nodoc:
module Zakuro
  # :nodoc:
  module Calculation
    # :nodoc:
    module Range
      # :nodoc:
      module Transfer
        #
        # GengouScroller 元号スクロール
        #
        module GengouScroller
          class << self
            #
            # 元号を年に設定する
            #
            # @param [Gengou::Scroll] scroll 元号スクロール
            # @param [Array<Base::Year>] years 年
            #
            def set(scroll:, years: [])
              years.each do |year|
                update_gengou_year(scroll: scroll, year: year)
              end
            end

            private

            #
            # 年の元号を更新する
            #
            # @param [Base::Year] year 年
            #
            def update_gengou_year(scroll:, year:)
              year.months.each_with_index do |month, index|
                scroll.run(month: month)
                gengou = scroll.to_gengou
                year.months[index] = Monthly::Month.new(
                  context: month.context,
                  month_label: month.month_label,
                  first_day: Monthly::FirstDay.new(
                    remainder: month.first_day.remainder,
                    western_date: gengou.start_date.clone
                  ),
                  solar_terms: month.solar_terms, gengou: gengou
                )
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zakuro-0.9.0 lib/zakuro/calculation/range/transfer/gengou_scroller.rb
zakuro-0.8.0 lib/zakuro/calculation/range/transfer/gengou_scroller.rb