class PrettyTime
Simple time serializer with two main functionalities:
-
Takes a time in seconds and converts it into a pretty string
-
Takes a pretty string and converts it into time in seconds
Dependencies: ActiveSupport
Constants
- H
Various mappings to allow one to pass in strings like:
4 hours 4 hrs 4 h Same goes for minutes and seconds.
- M
- S
Public Class Methods
config()
click to toggle source
Creates a new configuration instance
# File lib/pretty_time/pretty_time.rb, line 39 def self.config @config ||= PrettyTime::Configuration.new end
configuration() { |config| ... }
click to toggle source
Accepts a block and passes the configuration instance to the block
# File lib/pretty_time/pretty_time.rb, line 34 def self.configuration yield config end
dump(time_as_pretty_string)
click to toggle source
De-serializes(if you will) a pretty time into time in seconds Example:
PrettyTime.dump('2 minutes 10 seconds') # 130
# File lib/pretty_time/pretty_time.rb, line 24 def self.dump(time_as_pretty_string) pretty_time.dump(time_as_pretty_string) end
load(time_in_sec)
click to toggle source
Serializes(if you will) time in seconds supplied as integer to a pretty time string Example:
PrettyTime.load(130) # 2 minutes 10 seconds
# File lib/pretty_time/pretty_time.rb, line 16 def self.load(time_in_sec) pretty_time.load(time_in_sec) end
pretty_time()
click to toggle source
Creates an instance of itself if one does not exist
# File lib/pretty_time/pretty_time.rb, line 29 def self.pretty_time @pretty_time ||= Core.new end