Class: String

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

Overview

Extends the String class with time-related functionality

This implementaton assumes Time::Units and Numeric mixins are available.

Instance Method Summary collapse

Instance Method Details

#in_secondsFloat?

Converts a string representation of time to seconds

Examples:

"60m".in_seconds #=> 3600.0


14
15
16
17
18
# File 'lib/familia/core_ext.rb', line 14

def in_seconds
  q, u = scan(/([\d.]+)([smh])?/).flatten
  q &&= q.to_f and u ||= 's'
  q&.in_seconds(u)
end