class Zakuro::Calculation::Range::OperatedSolarTerms
OperatedSolarTerm 運用時二十四節気
Attributes
@return [Context] 暦コンテキスト
@return [Hash<String, SolarTerm>] 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
-
移動元の二十四節気:無効な大余小余あり(削除対象)
-
移動先の二十四節気:移動元からの二十四節気(追加対象)
@return [Array<Year>] 完全範囲(年データ)
Public Class Methods
月毎の移動方向を作成する
@param [Context] context 暦コンテキスト @param [Month] 月 @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気) @param [Operation::SolarTerm::Diretion] 二十四節気(移動)
# File lib/zakuro/calculation/range/operated_solar_terms.rb, line 123 def self.create_directions_each_month(context:, month:, directions: {}, direction: Operation::SolarTerm::Diretion.new) month.solar_terms.each do |solar_term| OperatedSolarTerms.push_source(context: context, directions: directions, direction: direction, solar_term: solar_term) end OperatedSolarTerms.push_destination(context: context, directions: directions, destination: direction.destination) end
年内の全ての月の移動方向を作成する
@param [Context] context 暦コンテキスト @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気) @param [Array<Month>] months 年内の全ての月
# File lib/zakuro/calculation/range/operated_solar_terms.rb, line 97 def self.create_directions_with_months(context:, directions: {}, months: []) months.each do |month| history = Operation.specify_history(western_date: month.western_date) next if history.invalid? direction = history.diffs.solar_term next if direction.invalid? OperatedSolarTerms.create_directions_each_month( context: context, directions: directions, direction: direction, month: month ) end end
移動先に有効な二十四節気(差し替える二十四節気)を生成する
@param [Context] context 暦コンテキスト @param [SolarTerm] solar_term 二十四節気(計算値) @param [Operation::SolarTerm::Direction] source 二十四節気(移動)
@return [SolarTerm] 二十四節気(運用値)
# File lib/zakuro/calculation/range/operated_solar_terms.rb, line 167 def self.created_source(context:, solar_term:, direction: Operation::SolarTerm::Direction.new) operated_solar_term = solar_term.clone remainder_class_name = context.resolver.remainder unless direction.invalid_days? # 二十四節気の大余をずらす operated_solar_term.remainder.add!( remainder_class_name.new(day: direction.days, minute: 0, second: 0) ) end operated_solar_term end
初期化
@param [Context] context 暦コンテキスト @param [Array<Year>] years 完全範囲(年データ)
# File lib/zakuro/calculation/range/operated_solar_terms.rb, line 35 def initialize(context:, years: []) @context = context @years = years @directions = {} end
移動元に無効な二十四節気(連番のみ指定)を指定する
@param [Context] context 暦コンテキスト @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気) @param [Operation::SolarTerm::Destination] destination 二十四節気(移動先)
# File lib/zakuro/calculation/range/operated_solar_terms.rb, line 189 def self.push_destination(context:, directions: {}, destination: Operation::SolarTerm::Destination.new) return if destination.invalid? solar_term_class = context.resolver.solar_term directions[destination.from.format] = solar_term_class.new( index: destination.index ) end
移動先に有効な二十四節気(差し替える二十四節気)を指定する
@param [Context] context 暦コンテキスト @param [SolarTerm] solar_term 二十四節気(計算値) @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気) @param [Operation::SolarTerm::Direction] source 二十四節気(移動)
# File lib/zakuro/calculation/range/operated_solar_terms.rb, line 144 def self.push_source(context:, solar_term:, directions: {}, direction: Operation::SolarTerm::Direction.new) source = direction.source return if source.invalid? return unless source.index == solar_term.index # 移動先に移動元の二十四節気を指定する directions[source.to.format] = OperatedSolarTerms.created_source( context: context, direction: direction, solar_term: solar_term ) end
Public Instance Methods
データ生成する
@return [<Type>] <description>
# File lib/zakuro/calculation/range/operated_solar_terms.rb, line 46 def create @directions = create_directions end
二十四節気の移動元/移動先を生成する
@return [Hash<String, SolarTerm>] 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
# File lib/zakuro/calculation/range/operated_solar_terms.rb, line 76 def create_directions directions = {} years.each do |year| OperatedSolarTerms.create_directions_with_months( context: context, directions: directions, months: year.months ) end directions end
二十四節気を取得する
@param [Western::Calendar] western_date 月初日の西暦日
@return [True] 対象あり @return [False] 対象なし @return [SolarTerm] 二十四節気
# File lib/zakuro/calculation/range/operated_solar_terms.rb, line 59 def get(western_date: Western::Calendar.new) solar_term_class = context.resolver.solar_term solar_term = @directions.fetch(western_date.format, solar_term_class.new) # 合致しない場合 return false, solar_term_class.new if solar_term.empty? # 合致した上で、二十四節気が移動元(削除対象)の場合 # 合致した上で、二十四節気が移動先(追加対象)の場合 [true, solar_term] end