Module: Helpers
- Defined in:
- lib/helpers.rb
Instance Method Summary collapse
- #clear_log(log) ⇒ Object
- #confirm(input = gets.chomp) ⇒ Object
- #log ⇒ Object
- #network? ⇒ Boolean
-
#time ⇒ Object
Formatted as: 03/07/2017 14:26.
- #write_log(log, lines) ⇒ Object
Instance Method Details
#clear_log(log) ⇒ Object
19 20 21 |
# File 'lib/helpers.rb', line 19 def clear_log(log) File.truncate(log, 0) end |
#confirm(input = gets.chomp) ⇒ Object
31 32 33 34 35 |
# File 'lib/helpers.rb', line 31 def confirm(input=gets.chomp) if ["y", "Y", "yes", "Yes", "YES", "k"].include? input true end end |
#log ⇒ Object
5 6 7 |
# File 'lib/helpers.rb', line 5 def log Dir.pwd + '/logs/output' end |
#network? ⇒ Boolean
14 15 16 17 |
# File 'lib/helpers.rb', line 14 def network? connection = Net::Ping::TCP.new('google.com', 80, 5) connection.ping? end |
#time ⇒ Object
Formatted as: 03/07/2017 14:26
10 11 12 |
# File 'lib/helpers.rb', line 10 def time Time.now.strftime("%m/%d/%Y %H:%M") end |
#write_log(log, lines) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/helpers.rb', line 23 def write_log(log, lines) File.open(log, 'a') do |file| lines.each do |line| file.puts "[#{time}]: #{line}" end end end |