Class: Zakuro::Japan::Type::Validation::Both::Year

Inherits:
Object
  • Object
show all
Defined in:
lib/zakuro/era/japan/type/validation/both/year.rb

Overview

Year 年

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash:) ⇒ Year

初期化

Parameters:

  • hash (Hash<String, Strin>)

    年情報



27
28
29
30
# File 'lib/zakuro/era/japan/type/validation/both/year.rb', line 27

def initialize(hash:)
  @japan = hash['japan']
  @western = hash['western']
end

Instance Attribute Details

#japanString (readonly)

Returns 和暦元号年.

Returns:

  • (String)

    和暦元号年



18
19
20
# File 'lib/zakuro/era/japan/type/validation/both/year.rb', line 18

def japan
  @japan
end

#westernString (readonly)

Returns 西暦年.

Returns:

  • (String)

    西暦年



20
21
22
# File 'lib/zakuro/era/japan/type/validation/both/year.rb', line 20

def western
  @western
end

Instance Method Details

#japan?True, False

和暦元号年を検証する

Returns:

  • (True)

    正しい

  • (False)

    正しくない



53
54
55
56
57
# File 'lib/zakuro/era/japan/type/validation/both/year.rb', line 53

def japan?
  return false unless @japan

  japan.is_a?(Integer)
end

#validateArray<String>

検証する

Returns:

  • (Array<String>)

    不正メッセージ



37
38
39
40
41
42
43
44
45
# File 'lib/zakuro/era/japan/type/validation/both/year.rb', line 37

def validate
  failed = []

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

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

  failed
end

#western?True, False

和暦元号年を検証する

Returns:

  • (True)

    正しい

  • (False)

    正しくない



65
66
67
68
69
# File 'lib/zakuro/era/japan/type/validation/both/year.rb', line 65

def western?
  return false unless @western

  western.is_a?(Integer)
end