Permalink
Browse files

document public API using YARD

  • Loading branch information...
1 parent a4e027f commit 0430622056af3da444968f67ae9b1f65f460a0c5 @jeremyw committed Jul 16, 2011
Showing with 16 additions and 2 deletions.
  1. +2 −0 .gitignore
  2. +1 −0 .yardopts
  3. +13 −2 lib/stamp.rb
View
@@ -1,3 +1,5 @@
*.gem
.bundle
+.yardoc
+doc
pkg/*
View
@@ -0,0 +1 @@
+--markup markdown
View
@@ -38,16 +38,27 @@ module Stamp
'%M' => '%S'
}
-
+ # Formats a date/time using a human-friendly example as a template.
+ #
+ # @param [String] example a human-friendly date/time example
+ # @return [String] the formatted date or time
+ #
+ # @example
+ # Date.new(2012, 12, 21).stamp("Jan 1, 1999") #=> "Dec 21, 2012"
def stamp(example)
strftime(strftime_format(example))
end
-
alias :stamp_like :stamp
alias :format_like :stamp
# Transforms the given string with example dates/times to a format string
# suitable for strftime.
+ #
+ # @param [String] example a human-friendly date/time example
+ # @return [String] a strftime-friendly format
+ #
+ # @example
+ # Date.today.strftime_format("Jan 1, 1999") #=> "%b %e, %Y"
def strftime_format(example)
# extract any substrings that look like times, like "23:59" or "8:37 am"
before, time_example, after = example.partition(TIME_REGEXP)

0 comments on commit 0430622

Please sign in to comment.