Class: Zakuro::Calculation::Base::Year
- Inherits:
-
Object
- Object
- Zakuro::Calculation::Base::Year
- Defined in:
- lib/zakuro/calculation/base/year.rb
Overview
Year 年
Direct Known Subclasses
Instance Attribute Summary collapse
-
#context ⇒ Context::Context
readonly
暦コンテキスト.
-
#months ⇒ Array<Month>
readonly
年内の全ての月.
-
#total_days ⇒ Integer
readonly
年の日数.
Instance Method Summary collapse
-
#commit ⇒ Object
年の日数を確定する.
-
#duplicated?(month:) ⇒ True
すでに登録済みの月と重複しているか判定する.
-
#initialize(context: Context::Context.new, months: [], total_days: 0) ⇒ Year
constructor
初期化.
-
#new_year_date ⇒ Western::Calendar
年初を取得する.
-
#next_year ⇒ MultiGengou
次年にする.
-
#push(month:) ⇒ Object
月を追加する.
-
#zodiac_name ⇒ String
十干十二支を取得する.
Constructor Details
#initialize(context: Context::Context.new, months: [], total_days: 0) ⇒ Year
初期化
33 34 35 36 37 |
# File 'lib/zakuro/calculation/base/year.rb', line 33 def initialize(context: Context::Context.new, months: [], total_days: 0) @context = context @months = months @total_days = total_days end |
Instance Attribute Details
#context ⇒ Context::Context (readonly)
Returns 暦コンテキスト.
20 21 22 |
# File 'lib/zakuro/calculation/base/year.rb', line 20 def context @context end |
#months ⇒ Array<Month> (readonly)
Returns 年内の全ての月.
22 23 24 |
# File 'lib/zakuro/calculation/base/year.rb', line 22 def months @months end |
#total_days ⇒ Integer (readonly)
Returns 年の日数.
24 25 26 |
# File 'lib/zakuro/calculation/base/year.rb', line 24 def total_days @total_days end |
Instance Method Details
#commit ⇒ Object
年の日数を確定する
42 43 44 45 46 47 48 49 |
# File 'lib/zakuro/calculation/base/year.rb', line 42 def commit @total_days = 0 months.each do |month| @total_days += month.days end self end |
#duplicated?(month:) ⇒ True
Note:
昨年11月1日から今年1月1日の前日までで、去年データと重複する場合は登録スキップする
すでに登録済みの月と重複しているか判定する
113 114 115 116 117 118 |
# File 'lib/zakuro/calculation/base/year.rb', line 113 def duplicated?(month:) months.each do |existed| return true if existed.same?(other: month) end false end |
#new_year_date ⇒ Western::Calendar
年初を取得する
70 71 72 73 74 75 76 |
# File 'lib/zakuro/calculation/base/year.rb', line 70 def new_year_date return Western::Calendar.new unless months return Western::Calendar.new if months.empty? months[0].western_date end |
#next_year ⇒ MultiGengou
次年にする
59 60 61 62 63 |
# File 'lib/zakuro/calculation/base/year.rb', line 59 def next_year @total_days = 0 self end |
#push(month:) ⇒ Object
月を追加する
95 96 97 98 99 100 101 |
# File 'lib/zakuro/calculation/base/year.rb', line 95 def push(month:) return if duplicated?(month: month) months.push(month) nil end |
#zodiac_name ⇒ String
十干十二支を取得する
83 84 85 86 87 88 |
# File 'lib/zakuro/calculation/base/year.rb', line 83 def zodiac_name date = new_year_date return '' if date.invalid? Cycle::Zodiac.year_name(western_year: date.year) end |