Module: Stamp
- Defined in:
- lib/stamp.rb,
lib/stamp/version.rb,
lib/stamp/translator.rb
Defined Under Namespace
Classes: StrftimeTranslator
Constant Summary collapse
- VERSION =
"0.4.0"
Class Method Summary collapse
-
.strftime_format(example, target = nil) ⇒ String
Transforms the given example dates/time format to a format string suitable for strftime.
Instance Method Summary collapse
-
#stamp(example) ⇒ String
(also: #stamp_like, #format_like)
Formats a date/time using a human-friendly example as a template.
-
#strftime_format(example) ⇒ String
Transforms the given example date/time format to a format string suitable for strftime.
Class Method Details
.strftime_format(example, target = nil) ⇒ String
Transforms the given example dates/time format to a format string suitable for strftime.
19 20 21 |
# File 'lib/stamp.rb', line 19 def self.strftime_format(example, target=nil) Stamp::StrftimeTranslator.new(target).translate(example) end |
Instance Method Details
#stamp(example) ⇒ String Also known as: stamp_like, format_like
Formats a date/time using a human-friendly example as a template.
30 31 32 |
# File 'lib/stamp.rb', line 30 def stamp(example) strftime(strftime_format(example)) end |
#strftime_format(example) ⇒ String
Transforms the given example date/time format to a format string suitable for strftime.
44 45 46 47 48 |
# File 'lib/stamp.rb', line 44 def strftime_format(example) # delegate to the class method, providing self as a target value to # support certain edge cases Stamp.strftime_format(example, self) end |