summaryrefslogtreecommitdiff
path: root/lib/custodian/util
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2015-03-09 13:19:47 +0000
committerSteve Kemp <steve@steve.org.uk>2015-03-09 13:19:47 +0000
commite716a49dabe2c086a97e2d8b3cffe5cf369ad026 (patch)
treee7e98125f89941db4c9d0f48f2df9c410467a3d8 /lib/custodian/util
parentaf2ee063abea8235a8cbd1448533e4f4fbc0d0af (diff)
Removed spaces inside parenthesis.
Diffstat (limited to 'lib/custodian/util')
-rw-r--r--lib/custodian/util/bytemark.rb2
-rw-r--r--lib/custodian/util/dns.rb10
-rw-r--r--lib/custodian/util/ping.rb16
-rw-r--r--lib/custodian/util/timespan.rb22
4 files changed, 25 insertions, 25 deletions
diff --git a/lib/custodian/util/bytemark.rb b/lib/custodian/util/bytemark.rb
index 07e5684..db3304d 100644
--- a/lib/custodian/util/bytemark.rb
+++ b/lib/custodian/util/bytemark.rb
@@ -26,7 +26,7 @@ module Custodian
#
# Is the named target inside the Bytemark IP-range?
#
- def self.inside?( target )
+ def self.inside?(target)
inside = false
if BYTEMARK_RANGES.any?{|range| range.include?(IPAddr.new(target))}
diff --git a/lib/custodian/util/dns.rb b/lib/custodian/util/dns.rb
index 2a0c705..b93fef5 100644
--- a/lib/custodian/util/dns.rb
+++ b/lib/custodian/util/dns.rb
@@ -20,7 +20,7 @@ module Custodian
#
# Return the reverse DNS for the specified IP address, nil on failure.
#
- def DNS.ip_to_hostname( ip )
+ def DNS.ip_to_hostname(ip)
resolved = nil
#
@@ -30,9 +30,9 @@ module Custodian
period = settings.timeout
begin
- timeout( period ) do
+ timeout(period) do
begin
- resolved = Socket.getnameinfo(Socket.sockaddr_in(80, ip) ).first
+ resolved = Socket.getnameinfo(Socket.sockaddr_in(80, ip)).first
rescue SocketError
resolved = nil
end
@@ -47,7 +47,7 @@ module Custodian
#
# Convert a hostname to an IP address, return nil on failure.
#
- def DNS.hostname_to_ip( hostname )
+ def DNS.hostname_to_ip(hostname)
resolved = nil
@@ -58,7 +58,7 @@ module Custodian
period = settings.timeout
begin
- timeout( period ) do
+ timeout(period) do
begin
Socket.getaddrinfo(hostname, 'echo').each do |a|
resolved = a[3] if a
diff --git a/lib/custodian/util/ping.rb b/lib/custodian/util/ping.rb
index cf79754..f8b7c75 100644
--- a/lib/custodian/util/ping.rb
+++ b/lib/custodian/util/ping.rb
@@ -24,13 +24,13 @@ module Custodian
#
# Save the hostname away, resolve it if possible.
#
- def initialize( hostname )
+ def initialize(hostname)
raise ArgumentError, 'Hostname must not be nil' if hostname.nil?
- raise ArgumentError, 'Hostname must be a String' unless hostname.kind_of?( String )
+ raise ArgumentError, 'Hostname must be a String' unless hostname.kind_of?(String)
@hostname = hostname
- @resolved = Custodian::Util::DNS.hostname_to_ip( hostname )
+ @resolved = Custodian::Util::DNS.hostname_to_ip(hostname)
end
@@ -47,7 +47,7 @@ module Custodian
# Does the hostname resolve to an IPv4 address?
#
def is_ipv4?
- if ( ! @resolved.nil? ) && ( @resolved =~ /^([0-9]+).([0-9]+).([0-9]+).([0-9]+)$/ )
+ if (! @resolved.nil?) && (@resolved =~ /^([0-9]+).([0-9]+).([0-9]+).([0-9]+)$/)
true
else
false
@@ -59,7 +59,7 @@ module Custodian
# Does the hostname resolve to an IPv6 address?
#
def is_ipv6?
- if ( ! @resolved.nil? ) && ( @resolved =~ /^([a-f0-9:]+)$/i )
+ if (! @resolved.nil?) && (@resolved =~ /^([a-f0-9:]+)$/i)
true
else
false
@@ -75,11 +75,11 @@ module Custodian
#
def run_ping
if is_ipv6?
- if ( system( "ping6 -c 1 #{@resolved} 2>/dev/null >/dev/null" ) == true )
+ if (system("ping6 -c 1 #{@resolved} 2>/dev/null >/dev/null") == true)
return true
end
- elsif( is_ipv4? )
- if ( system( "ping -c 1 #{@resolved} 2>/dev/null >/dev/null" ) == true )
+ elsif(is_ipv4?)
+ if (system("ping -c 1 #{@resolved} 2>/dev/null >/dev/null") == true)
return true
end
else
diff --git a/lib/custodian/util/timespan.rb b/lib/custodian/util/timespan.rb
index a033675..9b79867 100644
--- a/lib/custodian/util/timespan.rb
+++ b/lib/custodian/util/timespan.rb
@@ -12,13 +12,13 @@ module Custodian
#
# Convert an hour-string into a sane integer.
#
- def TimeSpan.to_hour( desc )
+ def TimeSpan.to_hour(desc)
#
# Handle PM times.
#
- if ( desc.kind_of? String ) &&
- ( desc =~ /([0-9]+)pm$/i )
+ if (desc.kind_of? String) &&
+ (desc =~ /([0-9]+)pm$/i)
desc = $1.dup.to_i + 12
end
@@ -26,15 +26,15 @@ module Custodian
# Handle AM times.
#
if desc.kind_of? String
- desc = desc.sub( /am$/, '' )
+ desc = desc.sub(/am$/, '')
desc = desc.to_i
end
#
# Ensure within a valid range
#
- raise ArgumentError, 'Integer required for time' unless( desc.kind_of? Integer )
- raise ArgumentError, "Invalid time: #{desc}" unless( ( desc >= 0 ) && ( desc <= 23 ) )
+ raise ArgumentError, 'Integer required for time' unless(desc.kind_of? Integer)
+ raise ArgumentError, "Invalid time: #{desc}" unless((desc >= 0) && (desc <= 23))
#
@@ -51,7 +51,7 @@ module Custodian
# to a hash of hours which are inside the
# range - inclusively.
#
- def TimeSpan.to_hours( p_start, p_end )
+ def TimeSpan.to_hours(p_start, p_end)
p_start = Custodian::Util::TimeSpan.to_hour(p_start)
p_end = Custodian::Util::TimeSpan.to_hour(p_end)
@@ -67,7 +67,7 @@ module Custodian
# Iterate over the hours. Store in a hash.
#
hour = p_start
- while( hour != p_end )
+ while(hour != p_end)
valid[hour] = 1
hour += 1
hour = 0 if hour > 23
@@ -87,7 +87,7 @@ module Custodian
# Given a starting hour, such as 10pm, and an ending hour,
# such as 4am, test whether a time is within that period.
#
- def TimeSpan.inside?( p_start, p_end, cur_hour = nil)
+ def TimeSpan.inside?(p_start, p_end, cur_hour = nil)
#
# Default to the current hour, if not specified.
@@ -107,13 +107,13 @@ module Custodian
# Get the expanded hours
#
valid =
- Custodian::Util::TimeSpan.to_hours( p_start, p_end )
+ Custodian::Util::TimeSpan.to_hours(p_start, p_end)
#
# Lookup to see if the specified hour is within the
# hours between the range.
#
- ( valid[cur_hour] == 1 )
+ (valid[cur_hour] == 1)
end
end