Class: ClassStatement

Inherits:
Node
  • Object
show all
Defined in:
lib/steamd/nodes/class_statement_node.rb

Overview

A parsed class statement

Contains the variables, class name, type

Examples:

A class

class Test { }

Instance Method Summary collapse

Instance Method Details

#nameObject

The name of the class



21
22
23
# File 'lib/steamd/nodes/class_statement_node.rb', line 21

def name
  class_name.text_value
end

#to_hashHash

Returns the class object as a hash

Returns:

  • (Hash)

    hash representation of the class



12
13
14
15
16
17
18
# File 'lib/steamd/nodes/class_statement_node.rb', line 12

def to_hash
  {
    name: name,
    type: type,
    variables: variables
  }
end

#typeObject

The class type

ie class Test<EMsg::Blah> {}



28
29
30
31
32
# File 'lib/steamd/nodes/class_statement_node.rb', line 28

def type
  types = elements.select { |el| el.is_a?(ClassType) }
  type = types.first
  type&.value
end

#variablesArray

Returns a list of variables

Returns:

  • (Array)

    variables



37
38
39
40
41
42
43
44
45
# File 'lib/steamd/nodes/class_statement_node.rb', line 37

def variables
  declerations = [first_var] + other.elements.map(&:decleration)

  variables = declerations.select do |node|
    node.is_a?(Variable)
  end

  variables.map!(&:to_hash)
end