Module: Rutty::Helpers
- Included in:
- Runner
- Defined in:
- lib/rutty/helpers.rb
Overview
Simple mixin module for miscellaneous methods that don’t fit in elsewhere.
Class Method Summary collapse
-
.get_version ⇒ String
Returns the version string contained in Version::STRING.
Instance Method Summary collapse
-
#check_installed! ⇒ void
Check to ensure the config dir exists.
-
#seconds_in_words(seconds_total) ⇒ String
Returns a string formatted to a more human-readable representation of a time difference in seconds.
Class Method Details
.get_version ⇒ String
Returns the version string contained in Version::STRING. Used by the rutty bin.
29 30 31 |
# File 'lib/rutty/helpers.rb', line 29 def self.get_version Rutty::Version::STRING end |
Instance Method Details
#check_installed! ⇒ void
Check to ensure the config dir exists. Method expects this module to be included in a class or module where self.config_dir is meaningful, such as Runner.
17 18 19 20 21 22 |
# File 'lib/rutty/helpers.rb', line 17 def check_installed! unless File.exists? self.config_dir raise Rutty::NotInstalledError.new %Q(Can't find conf directory at #{self.config_dir}. Run `rutty init' first. (Or rutty --help for usage)) end end |
#seconds_in_words(seconds_total) ⇒ String
Returns a string formatted to a more human-readable representation of a time difference in seconds.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rutty/helpers.rb', line 40 def seconds_in_words seconds_total hours = seconds_total / 3600 minutes = (seconds_total - (3600 * hours)) / 60 seconds = (seconds_total % (hours >= 1 ? (3600 * hours) : 60)) % 60 out = '' unless hours < 1 out << hours.to_s out << ((hours > 1) ? " hours " : " hour ") end unless minutes < 1 out << minutes.to_s out << ((minutes > 1) ? " minutes " : " minute ") end out << seconds.to_s out << ((seconds > 1) ? " seconds" : " second") out.strip end |