Namespace

Stamp

Constants

MEMOIZATION_CAP

Limits the number of formats that we memoize to prevent unbounded memory consumption.

VERSION

Public Instance Methods

format_like(example) click to toggle source
Alias for: stamp
memoize_stamp_emitters(example) click to toggle source

Memoizes the set of emitter objects for the given example in order to improve performance.

# File lib/stamp.rb, line 38
def memoize_stamp_emitters(example)
  @@memoized_stamp_emitters ||= {}
  @@memoized_stamp_emitters.clear if @@memoized_stamp_emitters.size > MEMOIZATION_CAP
  @@memoized_stamp_emitters[example] ||= stamp_emitters(example)
end
stamp(example) click to toggle source

Formats a date/time using a human-friendly example as a template.

@param [String] example a human-friendly date/time example @param [Hash] options @option options [Boolean] :memoize (true)

@return [String] the formatted date or time

@example

Date.new(2012, 12, 21).stamp("Jan 1, 1999") #=> "Dec 21, 2012"
# File lib/stamp.rb, line 30
def stamp(example)
  memoize_stamp_emitters(example).format(self)
end
Also aliased as: stamp_like, format_like
stamp_emitters(example) click to toggle source
# File lib/stamp.rb, line 44
def stamp_emitters(example)
  Translator.new.translate(example)
end
stamp_like(example) click to toggle source
Alias for: stamp

[Validate]

Generated with the Darkfish Rdoc Generator 2.