Module: DurationString
- Defined in:
- lib/duration_string.rb
Constant Summary collapse
- MULTIPLIERS =
{ "s" => 1, "m" => 60, "h" => 60 * 60, "d" => 60 * 60 * 24, "w" => 60 * 60 * 24 * 7 }
Class Method Summary collapse
Class Method Details
.to_seconds(duration) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/duration_string.rb', line 4 def to_seconds(duration) duration.scan(/(\d+)([smhdw])/).inject(0) do |seconds, match| num, dur_chr = match multiplier = MULTIPLIERS[dur_chr] seconds + num.to_i * multiplier end end |