Module: IPAddress::Conversions
- Extended by:
- Conversions
- Included in:
- IPAddress, IPAddress, Conversions, Prefix, Prefix
- Defined in:
- lib/ipaddress/conversions.rb
Instance Method Summary collapse
- #addr2ary(addr) ⇒ Object
- #addr2bits(addr) ⇒ Object
- #ary2addr(ary) ⇒ Object
- #ary2data(ary) ⇒ Object
- #ary2int(ary) ⇒ Object
- #bits2addr(bits) ⇒ Object
- #data2ary(data) ⇒ Object
- #data2bits(data) ⇒ Object
- #data2int(data) ⇒ Object
- #int2addr(int) ⇒ Object
- #int2ary(int) ⇒ Object
- #int2data(int) ⇒ Object
Instance Method Details
#addr2ary(addr) ⇒ Object
7 8 9 |
# File 'lib/ipaddress/conversions.rb', line 7 def addr2ary(addr) addr.split('.').map! { |i| i.to_i } end |
#addr2bits(addr) ⇒ Object
15 16 17 |
# File 'lib/ipaddress/conversions.rb', line 15 def addr2bits(addr) data2bits(ary2data(addr2ary(addr))) end |
#ary2addr(ary) ⇒ Object
11 12 13 |
# File 'lib/ipaddress/conversions.rb', line 11 def ary2addr(ary) ary.join('.') end |
#ary2data(ary) ⇒ Object
45 46 47 |
# File 'lib/ipaddress/conversions.rb', line 45 def ary2data(ary) ary.pack('C4') end |
#ary2int(ary) ⇒ Object
35 36 37 38 39 |
# File 'lib/ipaddress/conversions.rb', line 35 def ary2int(ary) int = 0 ary.each_with_index { |i, j| int += i << (3 - j) * 8 } int end |
#bits2addr(bits) ⇒ Object
19 20 21 |
# File 'lib/ipaddress/conversions.rb', line 19 def bits2addr(bits) ary2addr([bits].pack('B*').unpack('C4')) end |
#data2ary(data) ⇒ Object
41 42 43 |
# File 'lib/ipaddress/conversions.rb', line 41 def data2ary(data) data.unpack('C4').map! { |i| i.to_i } end |
#data2bits(data) ⇒ Object
23 24 25 |
# File 'lib/ipaddress/conversions.rb', line 23 def data2bits(data) data.unpack('B*').first end |
#data2int(data) ⇒ Object
49 50 51 |
# File 'lib/ipaddress/conversions.rb', line 49 def data2int(data) ary2int(data2ary(data)) end |
#int2addr(int) ⇒ Object
27 28 29 |
# File 'lib/ipaddress/conversions.rb', line 27 def int2addr(int) ary2addr(int2ary(int)) end |
#int2ary(int) ⇒ Object
31 32 33 |
# File 'lib/ipaddress/conversions.rb', line 31 def int2ary(int) data2ary(int2data(int)) end |
#int2data(int) ⇒ Object
53 54 55 |
# File 'lib/ipaddress/conversions.rb', line 53 def int2data(int) [int].pack('N') end |