module Zakuro::Calculation::Summary::Single

Single 一日

Public Class Methods

get(context:, date: Western::Calendar.new) click to toggle source

生成する

@param [Context] context 暦コンテキスト @param [Western::Calendar] date 西暦日

@return [Result::Single] 一日検索結果(和暦日)

# File lib/zakuro/calculation/summary/single.rb, line 27
def self.get(context:, date: Western::Calendar.new)
  full_range = Calculation::Range::FullRange.new(context: context, start_date: date)
  years = full_range.get

  calc_date = Calculation::Specifier::SingleDay.get(
    years: years, date: date
  )

  operated_range = Calculation::Range::OperatedRange.new(context: context, years: years)

  Result::Single.new(
    data: Calculation::Specifier::SingleDay.get(
      years: operated_range.get, date: date
    ),
    operation: create_operation(calc_date: calc_date)
  )
end

Private Class Methods

create_annnotations(operation_history: Operation::MonthHistory.new) click to toggle source

注釈情報を生成する

@param [Operation::MonthHistory] operation_history 変更履歴(月)

@return [Array<Result::Operation::Month::Annotation>] 注釈

# File lib/zakuro/calculation/summary/single.rb, line 112
def self.create_annnotations(operation_history: Operation::MonthHistory.new)
  annotations = []
  operation_history.annotations.each do |annotation|
    annotations.push(
      Result::Operation::Month::Annotation.new(
        description: annotation.description,
        note: annotation.note
      )
    )
  end

  annotations
end
create_operation(calc_date: Result::Data::SingleDay.new) click to toggle source

運用情報を生成する

@param [Result::Data::SingleDay] calc_date 和暦日(計算値)

@return [Result::Operation::Bundle] 運用情報

# File lib/zakuro/calculation/summary/single.rb, line 52
def self.create_operation(calc_date: Result::Data::SingleDay.new)
  first_day = calc_date.month.first_day.western_date
  operation_history = Operation.specify_history(western_date: first_day)

  operation_month = create_operation_month(operation_history: operation_history)

  Result::Operation::Bundle.new(
    operated: !operation_history.invalid?, month: operation_month, original: calc_date
  )
end
create_operation_month(operation_history: Operation::MonthHistory.new) click to toggle source

月履歴集約情報を生成する

@param [Operation::MonthHistory] operation_history 変更履歴(月)

@return [Result::Operation::Month::Bundle] 月履歴集約情報

# File lib/zakuro/calculation/summary/single.rb, line 71
def self.create_operation_month(operation_history: Operation::MonthHistory.new)
  return Result::Operation::Month::Bundle.new if operation_history.invalid?

  parent_operation_history = Operation.specify_history_by_id(
    id: operation_history.parent_id
  )

  Result::Operation::Month::Bundle.new(
    current: create_operation_month_history(operation_history: operation_history),
    parent: create_operation_month_history(operation_history: parent_operation_history)
  )
end
create_operation_month_history(operation_history: Operation::MonthHistory.new) click to toggle source

月別履歴情報を生成する

@param [Operation::MonthHistory] operation_history 変更履歴(月)

@return [Result::Operation::Month::History] 月別履歴情報

# File lib/zakuro/calculation/summary/single.rb, line 92
def self.create_operation_month_history(operation_history: Operation::MonthHistory.new)
  return Result::Operation::Month::History.new if operation_history.invalid?

  annotations = create_annnotations(operation_history: operation_history)

  reference = operation_history.reference
  Result::Operation::Month::History.new(
    id: operation_history.id, western_date: operation_history.western_date.format,
    page: reference.page, number: reference.number, annotations: annotations
  )
end