Class: Ruckus::Enum

Inherits:
Number show all
Defined in:
lib/ruckus/enum.rb

Constant Summary

Constants inherited from Number

Number::BASERX

Constants inherited from Parsel

Parsel::VERBOTEN

Instance Attribute Summary collapse

Attributes inherited from Number

#ascii, #endian, #pad, #radix, #value, #width

Attributes inherited from Parsel

#name, #parent, #rendered_offset, #rendering, #tag, #value

Instance Method Summary collapse

Methods inherited from Number

#ascii_capture, #ascii_to_s, #capture, #odd_width?, #odd_width_capture, #odd_width_first?, #odd_width_to_s, #resolve, #size, #span_bits, #span_offset, #to_s

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, #size, #visit, #where_am_i?

Constructor Details

#initialize(opts = {}) ⇒ Enum

Returns a new instance of Enum.



6
7
8
9
10
# File 'lib/ruckus/enum.rb', line 6

def initialize(opts={})
  super(opts)
  @enums ||= []
  raise "enums must be Enumerable" unless @enums.kind_of? Enumerable
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ruckus::Parsel

Instance Attribute Details

#enumsObject

Returns the value of attribute enums.



4
5
6
# File 'lib/ruckus/enum.rb', line 4

def enums
  @enums
end

Instance Method Details

#lookupObject



16
17
18
# File 'lib/ruckus/enum.rb', line 16

def lookup
  if (o=@enums[@value]).kind_of?(Hash) then o[:name] else o end
end

#to_human(indent = "") ⇒ Object



12
13
14
# File 'lib/ruckus/enum.rb', line 12

def to_human(indent="")
  "#{indent}#{@name} = #{@value}(#{@value.to_hex}) [ #{ ((n=lookup)? n : "???").to_s } ]"
end