Class: Ruckus::IP
Constant Summary
Constants inherited from Parsel
Instance Attribute Summary
Attributes inherited from Parsel
#name, #parent, #rendered_offset, #rendering, #tag, #value
Instance Method Summary collapse
- #capture(str) ⇒ Object
-
#initialize(opts = {}) ⇒ IP
constructor
A new instance of IP.
- #size ⇒ Object
- #to_s(off = nil) ⇒ Object
Methods inherited from Parsel
bytes_for_bits, coerce, #each_matching_selector, endian?, factory?, #find_containing, #find_tag, #find_tag_struct, #fixup, #in, #incomplete!, #index_for_selectors, #inspect, #matches_selector?, #method_missing, #native?, native?, #next, #out, #parent_structure, #permute, #prev, #resolve, #respond_to?, #root, #visit, #where_am_i?
Constructor Details
#initialize(opts = {}) ⇒ IP
Returns a new instance of IP.
9 10 11 12 |
# File 'lib/ruckus/ip.rb', line 9 def initialize(opts={}) opts[:value] ||= 0 super(opts) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Ruckus::Parsel
Instance Method Details
#capture(str) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/ruckus/ip.rb', line 29 def capture(str) cap = str.shift 4 sel = self.class.endian? == :little ? :reverse : :to_s @value = cap.send(sel).unpack("I").first return str end |
#size ⇒ Object
36 |
# File 'lib/ruckus/ip.rb', line 36 def size; 4; end |
#to_s(off = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ruckus/ip.rb', line 14 def to_s(off=nil) @rendered_offset = off || 0 val = resolve(@value) val = IPAddr.inet_addr(val) if val.kind_of? String r = [val].pack("I") r = r.reverse if self.class.endian? == :little if off return r, off + 4 else return r end end |