Class: Zakuro::Japan::Type::Validation::Both::Date
- Inherits:
-
Object
- Object
- Zakuro::Japan::Type::Validation::Both::Date
- Defined in:
- lib/zakuro/era/japan/type/validation/both/date.rb
Overview
Date 日
Instance Attribute Summary collapse
-
#japan ⇒ String
readonly
和暦日.
- #optional ⇒ True, False readonly
-
#western ⇒ String
readonly
西暦日.
Instance Method Summary collapse
-
#initialize(hash:, optional: false) ⇒ Date
constructor
初期化.
-
#japan? ⇒ True, False
和暦日を検証する.
-
#optional?(text: '') ⇒ True, False
省略可で省略されているか.
-
#validate ⇒ Array<String>
検証する.
-
#western? ⇒ True, False
西暦日を検証する.
Constructor Details
#initialize(hash:, optional: false) ⇒ Date
初期化
34 35 36 37 38 |
# File 'lib/zakuro/era/japan/type/validation/both/date.rb', line 34 def initialize(hash:, optional: false) @japan = hash['japan'] @western = hash['western'] @optional = optional end |
Instance Attribute Details
#japan ⇒ String (readonly)
Returns 和暦日.
22 23 24 |
# File 'lib/zakuro/era/japan/type/validation/both/date.rb', line 22 def japan @japan end |
#optional ⇒ True, False (readonly)
27 28 29 |
# File 'lib/zakuro/era/japan/type/validation/both/date.rb', line 27 def optional @optional end |
#western ⇒ String (readonly)
Returns 西暦日.
24 25 26 |
# File 'lib/zakuro/era/japan/type/validation/both/date.rb', line 24 def western @western end |
Instance Method Details
#japan? ⇒ True, False
和暦日を検証する
61 62 63 64 65 |
# File 'lib/zakuro/era/japan/type/validation/both/date.rb', line 61 def japan? return true if optional?(text: japan) Japan::Calendar.valid_date_text(text: japan) end |
#optional?(text: '') ⇒ True, False
省略可で省略されているか
87 88 89 90 91 92 93 |
# File 'lib/zakuro/era/japan/type/validation/both/date.rb', line 87 def optional?(text: '') return false unless optional return true if text == '' false end |
#validate ⇒ Array<String>
検証する
45 46 47 48 49 50 51 52 53 |
# File 'lib/zakuro/era/japan/type/validation/both/date.rb', line 45 def validate failed = [] failed.push("invalid japan date. #{japan}") unless japan? failed.push("invalid western date. #{western}") unless western? failed end |
#western? ⇒ True, False
西暦日を検証する
73 74 75 76 77 |
# File 'lib/zakuro/era/japan/type/validation/both/date.rb', line 73 def western? return true if optional?(text: western) Western::Calendar.valid_date_text(text: western) end |