Paiza レベルアップ問題集: 「日付のフォーマット Ruby編」 - https://paiza.jp/works/mondai/dateset/ruby/date_format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DateFormat | |
DATE_ORDER = %r{[0-9]{4}/[0-9]{2}/[0-9]{2}}.freeze | |
MONTH = [*(1..12).map { |n| n.to_s.rjust(2, '0') }].freeze | |
DAY = [*(1..31).map { |n| n.to_s.rjust(2, '0') }].freeze | |
class << self | |
def validate(date_string) | |
return 'No' unless date_string.match?(DATE_ORDER) | |
_year, month, day = date_string.split('/') | |
return 'No' unless MONTH.include?(month) | |
return 'No' unless DAY.include?(day) | |
'Yes' | |
end | |
end | |
end | |
puts DateFormat.validate(gets.chomp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment