Sha256: 69cbe3c3edcc04cad2be5723620a82c90b74333fe711aa354e8f99a4f99327f3

Contents?: true

Size: 1.94 KB

Versions: 4

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

require_relative './genka/cycle/remainder'
require_relative './genka/cycle/solar_term'
require_relative './genka/range/annual_range'

require_relative './gihou/cycle/remainder'
require_relative './gihou/cycle/solar_term'
require_relative './gihou/range/annual_range'

require_relative './daien/cycle/remainder'
require_relative './daien/cycle/solar_term'
require_relative './daien/range/annual_range'

require_relative './senmyou/cycle/remainder'
require_relative './senmyou/cycle/solar_term'
require_relative './senmyou/range/annual_range'

# :nodoc:
module Zakuro
  #
  # VersionClassResolver 暦リゾルバー
  #
  class VersionClassResolver
    attr_reader :version_name

    CLASSES = {
      'remainder' => 'Zakuro::$VERSION::Cycle::Remainder',
      'solar_term' => 'Zakuro::$VERSION::Cycle::SolarTerm',
      'annual_range' => 'Zakuro::$VERSION::Range::AnnualRange'
    }.freeze

    def initialize(version_name:)
      @version_name = version_name
    end

    def self.get_class(version_name:, class_name:)
      constant = CLASSES.fetch(class_name, '')

      raise ArgumentError.new, 'invalid class name' if constant == ''

      resolved_constant = constant.gsub('$VERSION', version_name)

      Object.const_get(resolved_constant)
    end

    #
    # 大余小余(暦別)クラスを返す
    #
    # @return [Class] 大余小余(暦別)クラス
    #
    def remainder
      VersionClassResolver.get_class(version_name: @version_name, class_name: 'remainder')
    end

    #
    # 二十四節気クラスを返す
    #
    # @return [Class] 二十四節気クラス
    #
    def solar_term
      VersionClassResolver.get_class(version_name: @version_name, class_name: 'solar_term')
    end

    #
    # 年間範囲クラスを返す
    #
    # @return [Class] 年間範囲クラス
    #
    def annual_range
      VersionClassResolver.get_class(version_name: @version_name, class_name: 'annual_range')
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zakuro-0.7.0 lib/zakuro/version/version_class_resolver.rb
zakuro-0.6.1 lib/zakuro/version/version_class_resolver.rb
zakuro-0.6.0 lib/zakuro/version/version_class_resolver.rb
zakuro-0.5.0 lib/zakuro/version/version_class_resolver.rb