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



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

def values
  @values
end

Class Method Details

.descriptorObject



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

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

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



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

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.to_i] = n; hash }
    @values_index[value]
  end
end

.valid_tag?(tag) ⇒ Boolean



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

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