Module: CommandTimer
- Defined in:
- lib/command_timer.rb,
lib/command_timer/parser.rb,
lib/command_timer/runner.rb,
lib/command_timer/command.rb,
lib/command_timer/version.rb
Defined Under Namespace
Classes: Command, Parser, Runner
Constant Summary
collapse
- VERSION =
"0.1.1"
Class Method Summary
collapse
Class Method Details
.ntp_time(server) ⇒ Object
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/command_timer.rb', line 8
def ntp_time(server)
ENV['PATH'].split(':').each do |path|
if File.exists?(path + '/ntpdate')
server ||= 'ntp.nict.jp'
return parse_time(%x[ntpdate -q #{server}].scan(/[0-9]{2}:[0-9]{2}:[0-9]{2}/).first)
end
end
puts "Warning: ntpdate not found and then use the local clock."
Time.now
end
|
.parse_time(str) ⇒ Object
19
20
21
22
23
|
# File 'lib/command_timer.rb', line 19
def parse_time(str)
hms = str.split(':').map(&:to_i)
now = Time.now
Time.new(now.year, now.month, now.day, hms[0], hms[1], hms[2])
end
|