Class: Utilities

Inherits:
Object
  • Object
show all
Defined in:
lib/easymanager/utilities.rb

Overview

Utility method that can be reused in the code

Class Method Summary collapse

Class Method Details

.elapsed_times(first, second) ⇒ Object



23
24
25
# File 'lib/easymanager/utilities.rb', line 23

def self.elapsed_times(first, second)
  ((DateTime.parse(first) - DateTime.parse(second)) * 24 * 60 * 60).to_i
end

.file_read(file) ⇒ Object



17
18
19
20
21
# File 'lib/easymanager/utilities.rb', line 17

def self.file_read(file)
  File.read(file)
rescue (Errno::ENOENT)
  nil
end

.parse_json(content) ⇒ Object



7
8
9
10
11
# File 'lib/easymanager/utilities.rb', line 7

def self.parse_json(content)
  JSON.parse(content)
rescue JSON::ParseError
  nil
end

.random_stringObject



13
14
15
# File 'lib/easymanager/utilities.rb', line 13

def self.random_string
  (0...8).map { rand(97..122).chr }.join
end