Sha256: 584aac93e422b4795767b9f40e023796217a5437101dfec040bcc61e9b740724

Contents?: true

Size: 1.93 KB

Versions: 11

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

# :nodoc:
module Zakuro
  # :nodoc:
  module Calculation
    # :nodoc:
    module Monthly
      #
      # MonthLabel 月表示情報
      #
      class MonthLabel
        # @return [True] 大の月(30日)
        # @return [False] 小の月(29日)
        attr_reader :is_many_days
        # @return [Integer] 月(xx月のxx)
        attr_reader :number
        # @return [True] 閏月
        # @return [False] 平月
        attr_reader :leaped

        # :reek:ControlParameter and :reek:BooleanParameter

        #
        # 初期化
        #
        # @param [Integer] number 月(xx月のxx)
        # @param [True, False] is_many_days 月の大小
        # @param [True, False] leaped 閏月/平月
        #
        def initialize(number: -1, is_many_days: false, leaped: false)
          # 月の大小
          @is_many_days = is_many_days
          # 月
          @number = number
          # 閏
          @leaped = leaped
        end

        #
        # 月の日数を返す
        #
        # @return [Integer] 日数
        #
        def days
          @is_many_days ? 30 : 29
        end

        #
        # 月の名前(大小)を返す
        #
        # @return [String] 月の名前(大小)
        #
        def days_name
          @is_many_days ? '大' : '小'
        end

        #
        # 一ヶ月戻す
        #
        # @return [True] 昨年
        # @return [False] 今年
        #
        def back_to_last_month
          @number -= 1

          return false if @number.positive?

          @number = 12

          true
        end

        #
        # 同一の月情報かを検証する
        #
        # @param [Month] other 他の月情報
        #
        # @return [True] 同一の月
        # @return [False] 異なる月
        #
        def same?(other:)
          @number == other.number && @leaped == other.leaped
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
zakuro-0.7.2 lib/zakuro/calculation/monthly/month_label.rb
zakuro-0.7.0 lib/zakuro/calculation/monthly/month_label.rb
zakuro-0.6.1 lib/zakuro/calculation/monthly/month_label.rb
zakuro-0.6.0 lib/zakuro/calculation/monthly/month_label.rb
zakuro-0.5.0 lib/zakuro/calculation/monthly/month_label.rb
zakuro-0.4.0 lib/zakuro/calculation/monthly/month_label.rb
zakuro-0.3.0 lib/zakuro/calculation/monthly/month_label.rb
zakuro-0.2.0 lib/zakuro/calculation/monthly/month_label.rb
zakuro-0.1.5 lib/zakuro/calculation/monthly/month_label.rb
zakuro-0.1.4 lib/zakuro/calculation/monthly/month_label.rb
zakuro-0.1.3 lib/zakuro/calculation/monthly/month_label.rb