Class: Kiwi::Definition
- Inherits:
-
Object
- Object
- Kiwi::Definition
- Defined in:
- lib/kiwi/definition.rb
Constant Summary collapse
- KIND_ENUM =
0
- KIND_STRUCT =
1
- KIND_MESSAGE =
2
Instance Attribute Summary collapse
-
#field_name_to_index ⇒ Object
readonly
Returns the value of attribute field_name_to_index.
-
#field_value_to_index ⇒ Object
readonly
Returns the value of attribute field_value_to_index.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#index ⇒ Object
Returns the value of attribute index.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #field(name) ⇒ Object
-
#initialize(name:, kind:, fields: []) ⇒ Definition
constructor
A new instance of Definition.
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_index ⇒ Object (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_index ⇒ Object (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 |
#fields ⇒ Object
Returns the value of attribute fields.
9 10 11 |
# File 'lib/kiwi/definition.rb', line 9 def fields @fields end |
#index ⇒ Object
Returns the value of attribute index.
9 10 11 |
# File 'lib/kiwi/definition.rb', line 9 def index @index end |
#kind ⇒ Object
Returns the value of attribute kind.
9 10 11 |
# File 'lib/kiwi/definition.rb', line 9 def kind @kind end |
#name ⇒ Object
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 |