Class: Protomsg::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/protomsg/attribute.rb

Constant Summary collapse

VALID_TYPES =
%w{int float string raw}

Instance Attribute Summary collapse

Instance Method Summary collapse

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(message_type, 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 = message_type
  @type = $1
  @name = $2
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/protomsg/attribute.rb', line 4

def name
  @name
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/protomsg/attribute.rb', line 4

def type
  @type
end

Instance Method Details

#finaliserObject



26
27
28
# File 'lib/protomsg/attribute.rb', line 26

def finaliser
  render_template('finalisers', 'finaliser')
end

#fixed_length?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/protomsg/attribute.rb', line 34

def fixed_length?
  !variable_length?
end

#getterObject



14
15
16
# File 'lib/protomsg/attribute.rb', line 14

def getter
  render_template('getters', 'getter')
end

#header_entryObject



22
23
24
# File 'lib/protomsg/attribute.rb', line 22

def header_entry
  render_template('header_entries', 'header_entry')
end

#setterObject



18
19
20
# File 'lib/protomsg/attribute.rb', line 18

def setter
  render_template('setters', 'setter')
end

#variable_length?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/protomsg/attribute.rb', line 30

def variable_length?
  %w{string raw}.include?(@type)
end