Class: IPRanger::IPRange
- Inherits:
-
Object
- Object
- IPRanger::IPRange
- Defined in:
- lib/ip_ranger/ip_range.rb
Instance Attribute Summary collapse
-
#finish ⇒ Object
readonly
Returns the value of attribute finish.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Instance Method Summary collapse
- #cidrs ⇒ Object
- #first ⇒ Object
-
#initialize(start, finish) ⇒ IPRange
constructor
A new instance of IPRange.
- #last ⇒ Object
Constructor Details
#initialize(start, finish) ⇒ IPRange
Returns a new instance of IPRange.
7 8 9 10 11 12 |
# File 'lib/ip_ranger/ip_range.rb', line 7 def initialize(start, finish) @start = IPAddress.new(start.is_a?(IPAddr) ? start : IPAddr.new(start)) @finish = IPAddress.new(finish.is_a?(IPAddr) ? finish : IPAddr.new(finish)) fail ArgumentError, 'IP sequence cannot contain both IPv4 and IPv6!' if @start.family != @finish.family end |
Instance Attribute Details
#finish ⇒ Object (readonly)
Returns the value of attribute finish.
5 6 7 |
# File 'lib/ip_ranger/ip_range.rb', line 5 def finish @finish end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
5 6 7 |
# File 'lib/ip_ranger/ip_range.rb', line 5 def start @start end |
Instance Method Details
#cidrs ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ip_ranger/ip_range.rb', line 14 def cidrs cidr_list = [] cidr_span = spanning_cidr if cidr_span.first < first exclude = first.pred cidr_list = cidr_partition(cidr_span, exclude).last cidr_span = cidr_list.pop end if cidr_span.last > last exclude = last.succ cidr_list += cidr_partition(cidr_span, exclude).first else cidr_list << cidr_span end cidr_list end |
#first ⇒ Object
34 35 36 |
# File 'lib/ip_ranger/ip_range.rb', line 34 def first start.first end |
#last ⇒ Object
38 39 40 |
# File 'lib/ip_ranger/ip_range.rb', line 38 def last finish.last end |