Module: FeCoreExt::CoreExt::DateClassMethods
- Included in:
- Date
- Defined in:
- lib/fe_core_ext/core_ext/date.rb
Instance Method Summary collapse
- #parsable?(string) ⇒ Boolean
- #parse_as_future(string) ⇒ Object
- #parse_gengo(string) ⇒ Object
- #parse_heisei(string) ⇒ Object
- #parse_ja(string) ⇒ Object
- #parse_nengappi(string) ⇒ Object
- #parse_reiwa(string) ⇒ Object
Instance Method Details
#parsable?(string) ⇒ Boolean
34 35 36 37 38 39 |
# File 'lib/fe_core_ext/core_ext/date.rb', line 34 def parsable?(string) parsed_hash = _parse(string) return true if parsed_hash.has_key?(:year) && parsed_hash.has_key?(:mon) false end |
#parse_as_future(string) ⇒ Object
41 42 43 44 |
# File 'lib/fe_core_ext/core_ext/date.rb', line 41 def parse_as_future(string) date = parse(string) date > current ? date : date + 1.year end |
#parse_gengo(string) ⇒ Object
60 61 62 |
# File 'lib/fe_core_ext/core_ext/date.rb', line 60 def parse_gengo(string) parse_heisei(string) || parse_reiwa(string) end |
#parse_heisei(string) ⇒ Object
46 47 48 49 50 |
# File 'lib/fe_core_ext/core_ext/date.rb', line 46 def parse_heisei(string) string.match('平成(\d+)年(\d+)月(\d+)日') do Date.new(::Regexp.last_match(1).to_i + 1988, ::Regexp.last_match(2).to_i, ::Regexp.last_match(3).to_i) end end |
#parse_ja(string) ⇒ Object
70 71 72 |
# File 'lib/fe_core_ext/core_ext/date.rb', line 70 def parse_ja(string) parse_nengappi(string) || parse_gengo(string) end |
#parse_nengappi(string) ⇒ Object
64 65 66 67 68 |
# File 'lib/fe_core_ext/core_ext/date.rb', line 64 def parse_nengappi(string) string.match(/(\d{4})年(\d+)月(\d+)日/) do Date.new(::Regexp.last_match(1).to_i, ::Regexp.last_match(2).to_i, ::Regexp.last_match(3).to_i) end end |
#parse_reiwa(string) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/fe_core_ext/core_ext/date.rb', line 52 def parse_reiwa(string) string.match('令和(\S+)年(\d+)月(\d+)日') do year = 1 if ::Regexp.last_match(1) == "元" year ||= ::Regexp.last_match(1).to_i Date.new(year + 2018, ::Regexp.last_match(2).to_i, ::Regexp.last_match(3).to_i) end end |