Module: StringExtensions
- Defined in:
- lib/duration_extensions.rb
Instance Method Summary collapse
- #-(other) ⇒ Object
- #duration ⇒ Object (also: #seconds)
- #looks_like_duration? ⇒ Boolean
- #looks_like_number? ⇒ Boolean
- #ordinal ⇒ Object
Instance Method Details
#-(other) ⇒ Object
51 52 53 54 55 |
# File 'lib/duration_extensions.rb', line 51 def -(other) if self.looks_like_duration? && other.looks_like_duration? (self.seconds - other.seconds).to_timecode end end |
#duration ⇒ Object Also known as: seconds
41 42 43 |
# File 'lib/duration_extensions.rb', line 41 def duration ActiveSupport::Duration.parse(self).value end |
#looks_like_duration? ⇒ Boolean
46 47 48 49 |
# File 'lib/duration_extensions.rb', line 46 def looks_like_duration? delimiters = Radiant::Config['race_results.delimiters'] || ':,.' true if self.match(/^[\d#{Regexp.escape(delimiters)}]+$/) end |
#looks_like_number? ⇒ Boolean
57 58 59 |
# File 'lib/duration_extensions.rb', line 57 def looks_like_number? Float(s) != nil rescue false end |
#ordinal ⇒ Object
61 62 63 |
# File 'lib/duration_extensions.rb', line 61 def ordinal to_i.ordinal end |