class Zakuro::Japan::Validator::Set

Set 元号セット情報の検証/展開

Attributes

end_date[R]

@return [String] 終了日

id[R]

@return [String] 元号セットID

list[R]

@return [Array<Hash<String, String>>] 元号情報

name[R]

@return [String] 元号セット名

Public Class Methods

new(hash:) click to toggle source

初期化

@param [Hash<String, Object>] hash 元号セット情報

# File lib/zakuro/era/japan/gengou/validator.rb, line 37
def initialize(hash:)
  @id = hash['id']
  @name = hash['name']
  @end_date = hash['end_date']
  @list = hash['list']
end

Public Instance Methods

id?() click to toggle source

IDを検証する

@return [True] 正しい @return [False] 正しくない

# File lib/zakuro/era/japan/gengou/validator.rb, line 69
def id?
  return false unless @id

  @id.is_a?(Integer)
end
list?() click to toggle source

元号情報を検証する

@return [True] 正しい @return [False] 正しくない

# File lib/zakuro/era/japan/gengou/validator.rb, line 103
def list?
  return false unless @list

  @list.is_a?(Array)
end
name?() click to toggle source

元号セット名を検証する

@return [True] 正しい @return [False] 正しくない

# File lib/zakuro/era/japan/gengou/validator.rb, line 81
def name?
  return false unless @name

  @name.is_a?(String)
end
validate() click to toggle source

検証する

@return [Array<String>] 不正メッセージ

# File lib/zakuro/era/japan/gengou/validator.rb, line 51
def validate
  failed = []
  failed.push("invalid id. #{id}") unless id?

  failed.push("invalid name. #{name}") unless name?

  failed.push("invalid end_date. #{end_date}") unless western_date?

  failed |= validate_list
  failed
end
validate_list() click to toggle source

元号情報を検証する

@return [True] 正しい @return [False] 正しくない

# File lib/zakuro/era/japan/gengou/validator.rb, line 115
def validate_list
  return ["invalid list. #{@list.class}"] unless list?

  failed = []
  list.each_with_index do |li, index|
    failed |= Gengou.new(hash: li, index: index).validate
  end
  failed
end
western_date?() click to toggle source

日付文字列を検証する

@return [True] 正しい @return [False] 正しくない

# File lib/zakuro/era/japan/gengou/validator.rb, line 93
def western_date?
  Western::Calendar.valid_date_string(str: @end_date)
end