Class: Protomsg::Attribute
- Inherits:
-
Object
- Object
- Protomsg::Attribute
- Defined in:
- lib/protomsg/attribute.rb
Constant Summary collapse
- VALID_TYPES =
%w{int float string raw}
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #finaliser ⇒ Object
- #fixed_length? ⇒ Boolean
- #getter ⇒ Object
- #header_entry ⇒ Object
-
#initialize(message_type, definition_line) ⇒ Attribute
constructor
A new instance of Attribute.
- #setter ⇒ Object
- #variable_length? ⇒ Boolean
Constructor Details
#initialize(message_type, definition_line) ⇒ Attribute
Returns a new instance of Attribute.
6 7 8 9 10 11 12 |
# File 'lib/protomsg/attribute.rb', line 6 def initialize(, definition_line) definition_line =~ /(\w+)\s+(\w+)/ or raise "Invalid attribute definition: '#{definition_line}'" VALID_TYPES.include?($1) or raise "Invalid attribute type: #{$1}" @message_type = @type = $1 @name = $2 end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/protomsg/attribute.rb', line 4 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/protomsg/attribute.rb', line 4 def type @type end |
Instance Method Details
#finaliser ⇒ Object
26 27 28 |
# File 'lib/protomsg/attribute.rb', line 26 def finaliser render_template('finalisers', 'finaliser') end |
#fixed_length? ⇒ Boolean
34 35 36 |
# File 'lib/protomsg/attribute.rb', line 34 def fixed_length? !variable_length? end |
#getter ⇒ Object
14 15 16 |
# File 'lib/protomsg/attribute.rb', line 14 def getter render_template('getters', 'getter') end |
#header_entry ⇒ Object
22 23 24 |
# File 'lib/protomsg/attribute.rb', line 22 def header_entry render_template('header_entries', 'header_entry') end |
#setter ⇒ Object
18 19 20 |
# File 'lib/protomsg/attribute.rb', line 18 def setter render_template('setters', 'setter') end |
#variable_length? ⇒ Boolean
30 31 32 |
# File 'lib/protomsg/attribute.rb', line 30 def variable_length? %w{string raw}.include?(@type) end |