class String
Public Instance Methods
as_hours()
click to toggle source
Converts a timestring to hours
# File lib/service/utils/wrappers/string.rb, line 17 def as_hours return self.as_seconds.to_f / 3600 end
as_seconds()
click to toggle source
Converts a timestring to seconds with milliseconds part support
# File lib/service/utils/wrappers/string.rb, line 3 def as_seconds # Check if input string has a valid format raise "Invalid timestring format: #{self}" if not self.match(/^\d{1,}:[0-5]?[0-9](:[0-5]?[0-9](\.\d+)?)?$/) # Split input string by ":" char and convert each part to float hours, minutes, seconds = self.split(":").map(&:to_f) # Seconds part could be missing, so set it to 0 by default seconds ||= 0 return hours * 3600 + minutes * 60 + seconds end
blank?()
click to toggle source
# File lib/service/utils/wrappers/string.rb, line 21 def blank? return self.strip == "" end
is_false?()
click to toggle source
# File lib/service/utils/wrappers/string.rb, line 33 def is_false? return ["n", "no", "f", "false"].include?(self.strip.downcase) end
is_true?()
click to toggle source
# File lib/service/utils/wrappers/string.rb, line 29 def is_true? return ["y", "yes", "t", "true"].include?(self.strip.downcase) end
present?()
click to toggle source
# File lib/service/utils/wrappers/string.rb, line 25 def present? return (not self.blank?) end