Module: Lite::Ruby::DateHelper
Instance Method Summary collapse
- #format(string = nil) ⇒ Object
- #stamp(key = nil) ⇒ Object (also: #to_format)
Instance Method Details
#format(string = nil) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/lite/ruby/helpers/date_helper.rb', line 89 def format(string = nil) string ||= default_format delimiters = string.scan(/\W+/) formatters = string.scan(/[a-z0-9_]+/i) string = formatters.map { |key| "%#{format_for(key.to_sym)}#{delimiters.shift}" } strftime(string.join) end |
#stamp(key = nil) ⇒ Object Also known as: to_format
97 98 99 100 |
# File 'lib/lite/ruby/helpers/date_helper.rb', line 97 def stamp(key = nil) key = stamp_for(key&.to_sym || default_stamp) strftime(key) end |