class FMParser::MessageNode
Attributes
enums[R]
label[R]
messages[R]
name[R]
scalars[R]
type[R]
Public Class Methods
new(name:, type:, label:, scalars: [], enums: [], messages: [])
click to toggle source
@param [String | Symbol | nil] name @param [Class] type represents the message type of protobuf @param [String | Symbol | nil] label
# File lib/fmparser/node.rb, line 49 def initialize(name:, type:, label:, scalars: [], enums: [], messages: []) @name = name ? name.to_sym : name @type = type @label = label ? label.to_sym : label @scalars = scalars @enums = enums @messages = messages end
Public Instance Methods
==(other)
click to toggle source
# File lib/fmparser/node.rb, line 92 def ==(other) self.class == other.class && self.name == other.name && self.type == other.type && self.label == other.label && self.scalars == other.scalars && self.enums == other.enums && self.messages == other.messages end
children()
click to toggle source
# File lib/fmparser/node.rb, line 87 def children @children ||= @messages.map { |m| [m.name, m] }.to_h end
field_names()
click to toggle source
@return [<Symbol>]
# File lib/fmparser/node.rb, line 67 def field_names fields.map(&:name) end
fields()
click to toggle source
@return [<FMParser::Node>]
# File lib/fmparser/node.rb, line 62 def fields scalars + enums + messages end
get_child(field)
click to toggle source
@param [String | Symbol] field @return [FMParser::MessageNode | nil]
# File lib/fmparser/node.rb, line 81 def get_child(field) f = field.to_sym validate!(f) children[f] end
has?(field)
click to toggle source
@param [String | Symbol] field @return [Boolean]
# File lib/fmparser/node.rb, line 73 def has?(field) f = field.to_sym validate!(f) field_names.include?(f) end
Private Instance Methods
valid_fields()
click to toggle source
@return [<Symbol>]
# File lib/fmparser/node.rb, line 113 def valid_fields @valid_fields ||= @type.descriptor.entries.map(&:name).map(&:to_sym) end
validate!(field)
click to toggle source
@param [Symbol] @raise [InvalidFieldError]
# File lib/fmparser/node.rb, line 106 def validate!(field) if !valid_fields.include?(field) raise InvalidParameterError.new("There is no \"#{field}\" field in the #{@type} class") end end