Class: Kiwi::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/kiwi/definition.rb

Constant Summary collapse

KIND_ENUM =
0
KIND_STRUCT =
1
KIND_MESSAGE =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, kind:, fields: []) ⇒ Definition

Returns a new instance of Definition.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/kiwi/definition.rb', line 12

def initialize(name:, kind:, fields: [])
  @name = name
  @kind = kind
  @fields = fields
  @index = 0
  @field_name_to_index = {}
  @field_value_to_index = {}

  @fields.each_with_index do |field, i|
    field_value_to_index[field.value] = i
    field_name_to_index[field.name] = i
  end
end

Instance Attribute Details

#field_name_to_indexObject (readonly)

Returns the value of attribute field_name_to_index.



10
11
12
# File 'lib/kiwi/definition.rb', line 10

def field_name_to_index
  @field_name_to_index
end

#field_value_to_indexObject (readonly)

Returns the value of attribute field_value_to_index.



10
11
12
# File 'lib/kiwi/definition.rb', line 10

def field_value_to_index
  @field_value_to_index
end

#fieldsObject

Returns the value of attribute fields.



9
10
11
# File 'lib/kiwi/definition.rb', line 9

def fields
  @fields
end

#indexObject

Returns the value of attribute index.



9
10
11
# File 'lib/kiwi/definition.rb', line 9

def index
  @index
end

#kindObject

Returns the value of attribute kind.



9
10
11
# File 'lib/kiwi/definition.rb', line 9

def kind
  @kind
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/kiwi/definition.rb', line 9

def name
  @name
end

Instance Method Details

#field(name) ⇒ Object



26
27
28
29
30
# File 'lib/kiwi/definition.rb', line 26

def field(name)
  if idx = field_name_to_index[name]
    fields[idx]
  end
end