Class: PrettyTime

Inherits:
Object
  • Object
show all
Defined in:
lib/pretty_time/pretty_time.rb

Overview

Simple time serializer with two main functionalities:

  1. Takes a time in seconds and converts it into a pretty string

  2. Takes a pretty string and converts it into time in seconds

Dependencies: ActiveSupport

Defined Under Namespace

Classes: Configuration, Core, Hours, Minutes, Seconds, UnitOfTime

Constant Summary collapse

H =

Various mappings to allow one to pass in strings like:

4 hours 4 hrs 4 h Same goes for minutes and seconds.

Hrs = Hr = Hour = Hours
M =
Mins = Min = Minute = Minutes
S =
Secs = Sec = Second = Seconds

Class Method Summary collapse

Class Method Details

.configObject

Creates a new configuration instance



39
40
41
# File 'lib/pretty_time/pretty_time.rb', line 39

def self.config
  @config ||= PrettyTime::Configuration.new
end

.configuration {|config| ... } ⇒ Object

Accepts a block and passes the configuration instance to the block

Yields:



34
35
36
# File 'lib/pretty_time/pretty_time.rb', line 34

def self.configuration
  yield config
end

.dump(time_as_pretty_string) ⇒ Object

De-serializes(if you will) a pretty time into time in seconds Example:

PrettyTime.dump('2 minutes 10 seconds')  # 130


24
25
26
# 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) ⇒ Object

Serializes(if you will) time in seconds supplied as integer to a pretty time string Example:

PrettyTime.load(130)  # 2 minutes 10 seconds


16
17
18
# File 'lib/pretty_time/pretty_time.rb', line 16

def self.load(time_in_sec)
  pretty_time.load(time_in_sec)
end

.pretty_timeObject

Creates an instance of itself if one does not exist



29
30
31
# File 'lib/pretty_time/pretty_time.rb', line 29

def self.pretty_time
  @pretty_time ||= Core.new
end