Sha256: a6da7d54da31a36eacee9b53d6b7622b3555f652212d035ee03ad867fecf767b
Contents?: true
Size: 1.91 KB
Versions: 7
Compression:
Stored size: 1.91 KB
Contents
= Periodic == Installation $ sudo gem sources -a http://gems.github.com $ sudo gem install farski-periodic == Usage ==== Parser Periodic will parse out natural language strings representing durations using different units of time, and return the total number of seconds. When using test labels, it will do it's best to look for any of the following units: seconds, minutes, hours, days, weeks, months, years, decades, centuries, millennia. Units can appear in any order in the string, but should only appear once. When using a digital format (10:30), the parser will default to the smallest sensible units (e.g. 10 minutes 30 seconds), but this can be overridden using the :bias option (e.g. 10 centuries 30 decades). Valid options for the :bias are symbols of those units mentioned in the previous paragraph. If a bias is explicitly defined that is too precise for the given string, the smallest sensible unit will be subsituted >> Periodic.parse('1 minute') => 60 >> Periodic.parse('60min') => 3600 >> Periodic.parse('1:30') => 90 >> Periodic.parse('1:30', :bias => :hours) => 5400 ==== Printer The printer accepts a Float or Integer number of seconds, and returns a formatted string. The default is a digital format that includes all available units in the printer (seconds minutes hours days weeks months years), and drops any zero-value units. Customized formats can be passed into the printer as a string with any number of directives. Exclamation points (!) can be used to force non-zero unit to appear in the output string. The available directives /%s/, /%m/, /%h/, /%d/, /%w/, /%n/, /%y/ >> Periodic.output(120) => '2:00' >> Periodic.output((60*60), "!%d!:%h:%m:%s") => '00:01:00:00' >> Periodic.output((60*60), "%hh %s!s") => '1h 0s' Nil is returned if the string can't be parsed == COPYRIGHT Copyright (c) 2008 Chris Kalafarski. See LICENSE for details.
Version data entries
7 entries across 7 versions & 1 rubygems