Class: Protobuf::Enum

Inherits:
Object
  • Object
show all
Extended by:
Protoable
Defined in:
lib/protobuf/message/enum.rb

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Protoable

defined_filenames, defined_in, proto_contents, proto_filenames, retrieve_header

Class Attribute Details

.valuesObject (readonly)

Returns the value of attribute values.



10
11
12
# File 'lib/protobuf/message/enum.rb', line 10

def values
  @values
end

Class Method Details

.descriptorObject



27
28
29
# File 'lib/protobuf/message/enum.rb', line 27

def descriptor
  @descriptor ||= Descriptor::EnumDescriptor.new(self)
end

.name_by_value(value) ⇒ Object Also known as: get_name_by_tag



12
13
14
15
16
17
18
19
# File 'lib/protobuf/message/enum.rb', line 12

def name_by_value(value)
  if not defined?(@values)
    constants.find {|c| const_get(c) == value}  # for compatibility
  else
    @values_index ||= @values.inject({}) {|hash, (n, v)| hash[v.value] = n; hash }
    @values_index[value]
  end
end

.valid_tag?(tag) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/protobuf/message/enum.rb', line 23

def valid_tag?(tag)
  !! name_by_value(tag)
end