Sha256: c95d11e2ebbdbec0aacafdda0b5866d56a88c807b8d0e0612fdb9aff7656b595

Contents?: true

Size: 688 Bytes

Versions: 5

Compression:

Stored size: 688 Bytes

Contents

module Alblogs
  module Utils
    module_function

    def parse_time_offset(str)
      if str =~ /min/
        str.sub(/ *min.*/, '').to_i * 60
      elsif str =~ /hour/
        str.sub(/ *hour.*/, '').to_i * 3600
      elsif str =~ /day/
        str.sub(/ *day.*/, '').to_i * 86400
      else
        nil
      end
    end

    def time_ago(now, str)
      if offset = parse_time_offset(str)
        time = now - offset
        time - (time.to_i % 60) # round to the start of the minute
      else
        Time.parse(str).utc
      end
    end

    def run_or_die(cmd)
      res = `#{cmd}`
      raise("command failed with #{$?}, #{cmd}") unless $?.success?
      res
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alblogs-0.1.8 lib/alblogs/utils.rb
alblogs-0.1.7 lib/alblogs/utils.rb
alblogs-0.1.4 lib/alblogs/utils.rb
alblogs-0.1.2 lib/alblogs/utils.rb
alblogs-0.1.0 lib/alblogs/utils.rb