Module: PAC::Functions

Defined in:
lib/pac/functions.rb

Constant Summary collapse

DAYS =
{ "MON" => 1, "TUE" => 2, "WED" => 3, "THU" => 4, "FRI" => 5, "SAT" => 6, "SUN" => 7 }
MONTHS =
{ "JAN" => 1, "FEB" => 2, "MAR" => 3, "APR" => 4, "MAY" => 5, "JUN" => 6,
"JUL" => 7, "AUG" => 8, "SEP" => 9, "OCT" => 10, "NOV" => 11, "DEC" => 12 }

Class Method Summary collapse

Class Method Details

.dateRange(*args) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/pac/functions.rb', line 55

def dateRange(*args)
  time = Time.now
  time = time.utc if args.last == "GMT" and args.pop

  case args.size
  when 1
    check_date_part(time, args[0])
  when 2
    check_date_part(time, args[0]..args[1])
  when 4
    check_date_part(time, args[0]..args[2]) and
    check_date_part(time, args[1]..args[3])
  when 6
    check_date_part(time, args[0]..args[3]) and
    check_date_part(time, args[1]..args[4]) and
    check_date_part(time, args[2]..args[5])
  else
    raise ArgumentError, "wrong number of arguments"
  end
end

.dnsDomainIs(host, domain) ⇒ Object



16
17
18
# File 'lib/pac/functions.rb', line 16

def dnsDomainIs(host, domain)
  host.end_with? domain
end

.dnsDomainLevels(host) ⇒ Object



40
41
42
# File 'lib/pac/functions.rb', line 40

def dnsDomainLevels(host)
  host.scan(".").size
end

.dnsResolve(host) ⇒ Object



32
33
34
# File 'lib/pac/functions.rb', line 32

def dnsResolve(host)
  resolve_host(host)
end

.isInNet(host, pattern, mask) ⇒ Object



28
29
30
# File 'lib/pac/functions.rb', line 28

def isInNet(host, pattern, mask)
  IPAddr.new(pattern).mask(mask).include? resolve_host(host)
end

.isPlainHostName(host) ⇒ Object



12
13
14
# File 'lib/pac/functions.rb', line 12

def isPlainHostName(host)
  not host.include? "."
end

.isResolvable(host) ⇒ Object



24
25
26
# File 'lib/pac/functions.rb', line 24

def isResolvable(host)
  !!resolve_host(host)
end

.localHostOrDomainIs(host, hostdom) ⇒ Object



20
21
22
# File 'lib/pac/functions.rb', line 20

def localHostOrDomainIs(host, hostdom)
  host == hostdom or hostdom.include? host
end

.myIpAddressObject



36
37
38
# File 'lib/pac/functions.rb', line 36

def myIpAddress()
  resolve_host(Socket.gethostname)
end

.shExpMatch(str, shexp) ⇒ Object



44
45
46
# File 'lib/pac/functions.rb', line 44

def shExpMatch(str, shexp)
  ::File.fnmatch(shexp, str)
end

.timeRange(*args) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/pac/functions.rb', line 76

def timeRange(*args)
  time = Time.now
  time = time.utc if args.last == "GMT" and args.pop

  case args.size
  when 1
    time.hour == args[0]
  when 2
    (args[0]..args[1]).include? time.hour
  when 4
    (args[0]..args[2]).include? time.hour and
    (args[1]..args[3]).include? time.min
  when 6
    (args[0]..args[3]).include? time.hour and
    (args[1]..args[4]).include? time.min  and
    (args[2]..args[5]).include? time.sec
  else
    raise ArgumentError, "wrong number of arguments"
  end
end

.weekdayRange(wd1, wd2 = nil, gmt = nil) ⇒ Object



48
49
50
51
52
53
# File 'lib/pac/functions.rb', line 48

def weekdayRange(wd1, wd2 = nil, gmt = nil)
  time = Time.now
  time = time.utc if gmt == "GMT"

  (DAYS[wd1]..DAYS[wd2 || wd1]).include? time.wday
end