Class: TLV::TLV::Field
- Inherits:
-
Object
- Object
- TLV::TLV::Field
- Defined in:
- lib/tlv/field.rb
Instance Attribute Summary collapse
-
#display_name ⇒ Object
Returns the value of attribute display_name.
-
#length ⇒ Object
Returns the value of attribute length.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #define_accessor(clazz) ⇒ Object
-
#initialize(clazz, desc, name = nil, len = 0) ⇒ Field
constructor
A new instance of Field.
- #parse(tlv, bytes, length) ⇒ Object
Constructor Details
#initialize(clazz, desc, name = nil, len = 0) ⇒ Field
Returns a new instance of Field.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/tlv/field.rb', line 5 def initialize clazz, desc, name=nil, len=0 @length=len unless name name = desc.gsub(/\s/, "_") name = name.gsub(/\W/, "") name = name.downcase.to_sym end @name = name @display_name = desc define_accessor clazz end |
Instance Attribute Details
#display_name ⇒ Object
Returns the value of attribute display_name.
4 5 6 |
# File 'lib/tlv/field.rb', line 4 def display_name @display_name end |
#length ⇒ Object
Returns the value of attribute length.
4 5 6 |
# File 'lib/tlv/field.rb', line 4 def length @length end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/tlv/field.rb', line 4 def name @name end |
Instance Method Details
#define_accessor(clazz) ⇒ Object
19 20 21 |
# File 'lib/tlv/field.rb', line 19 def define_accessor clazz #raise "Not primitive: #{clazz.to_s}, TAG=#{TLV.b2s clazz.tag}" unless clazz.primitive? end |
#parse(tlv, bytes, length) ⇒ Object
16 17 18 |
# File 'lib/tlv/field.rb', line 16 def parse tlv, bytes, length raise "not implemented! use subclass" end |