Class: IPRange
Constant Summary collapse
- @@log =
init_logger(STDOUT)
Instance Attribute Summary collapse
-
#first ⇒ Object
readonly
Returns the value of attribute first.
-
#last ⇒ Object
readonly
Returns the value of attribute last.
-
#vrange ⇒ Object
readonly
Returns the value of attribute vrange.
Instance Method Summary collapse
-
#in_range?(cip) ⇒ Boolean
check IP in range ?.
-
#initialize(args) ⇒ IPRange
constructor
create an IP-range.
- #irange ⇒ Object
Methods included from Logging
init_logger, log_level=, log_target=
Constructor Details
#initialize(args) ⇒ IPRange
create an IP-range
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ip_range.rb', line 55 def initialize(args) @log = @@log if args && args.length >= 2 #first IP @first = ip_to_number args[0] #last IP @last = ip_to_number args[1] if @last && @first && ( @last < @first ) @log.error('ERROR! Last IP is smaller than first. Aborting!') exit false end @vrange = args[0,2] end end |
Instance Attribute Details
#first ⇒ Object (readonly)
Returns the value of attribute first.
71 72 73 |
# File 'lib/ip_range.rb', line 71 def first @first end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
71 72 73 |
# File 'lib/ip_range.rb', line 71 def last @last end |
#vrange ⇒ Object (readonly)
Returns the value of attribute vrange.
71 72 73 |
# File 'lib/ip_range.rb', line 71 def vrange @vrange end |
Instance Method Details
#in_range?(cip) ⇒ Boolean
check IP in range ?
46 47 48 |
# File 'lib/ip_range.rb', line 46 def in_range?(cip) (@first..@last) === ip_to_number(cip) end |
#irange ⇒ Object
50 51 52 |
# File 'lib/ip_range.rb', line 50 def irange() [@first, @last] end |