Class: Net::Address::Mask
- Inherits:
-
Object
- Object
- Net::Address::Mask
- Includes:
- Comparable
- Defined in:
- lib/net/address/mask.rb
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(mask) ⇒ Mask
constructor
A new instance of Mask.
- #to_cidr ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(mask) ⇒ Mask
Returns a new instance of Mask.
11 12 13 14 15 |
# File 'lib/net/address/mask.rb', line 11 def initialize(mask) mask = mask.nil? ? 0 : mask @mask = parse_mask(mask) raise ArgumentError, "Not valid Net::Address::Mask #{mask}" unless 0 <= @mask.to_i and @mask.to_i <= 32 end |
Instance Method Details
#<=>(other) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/net/address/mask.rb', line 29 def <=>(other) begin other = self.class.new(other) unless other.is_a? self.class rescue nil end self.to_i <=> other.to_i end |
#to_cidr ⇒ Object
25 26 27 |
# File 'lib/net/address/mask.rb', line 25 def to_cidr @mask.to_i end |
#to_i ⇒ Object
21 22 23 |
# File 'lib/net/address/mask.rb', line 21 def to_i (0xFFFFFFFF << (32 - @mask.to_i)) & 0xFFFFFFFF end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/net/address/mask.rb', line 17 def to_s [self.to_i].pack('N').unpack('C*').join '.' end |