#duration-formatter
A simple gem to parse minutes into a readable format using ruby-duration.
This library is tested with the following Rubies: 2.2.5, 2.3.1.
Add it to your Gemfile with:
gem 'duration-formatter'
Run the bundle install
command in your terminal to install it.
The gem exposes a class FormattedDuration
which takes the passed minutes to determine the format. Calling format
on the instance returns the formatted duration. Examples:
# Full units
FormattedDuration.new(10080).format # => 1 week
FormattedDuration.new(1440).format # => 1 day
FormattedDuration.new(240).format # => 4 hours
FormattedDuration.new(20).format # => 20 minutes
# Composition
FormattedDuration.new(15840).format # => 1 week, 4 days
FormattedDuration.new(1450).format # => 1 day, 10 minutes
FormattedDuration.new(241).format # => 4 hours, 1 minute
You can also force a constraint upon the format.
FormattedDuration.new(11520, :days).format # => 15 days (not "2 weeks, 1 day")
FormattedDuration.new(1440, :hours).format # => 24 hours
FormattedDuration.new(80, :minutes).format # => 80 minutes
This library is released under the MIT License.