Class: Spektr::Exp::Receiver

Inherits:
Object
  • Object
show all
Defined in:
lib/spektr/exp/send.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast) ⇒ Receiver

Returns a new instance of Receiver.



100
101
102
103
# File 'lib/spektr/exp/send.rb', line 100

def initialize(ast)
  @children = []
  set_attributes(ast)
end

Instance Attribute Details

#astObject

Returns the value of attribute ast.



98
99
100
# File 'lib/spektr/exp/send.rb', line 98

def ast
  @ast
end

#childrenObject

Returns the value of attribute children.



98
99
100
# File 'lib/spektr/exp/send.rb', line 98

def children
  @children
end

#expandedObject

Returns the value of attribute expanded.



98
99
100
# File 'lib/spektr/exp/send.rb', line 98

def expanded
  @expanded
end

#nameObject

Returns the value of attribute name.



98
99
100
# File 'lib/spektr/exp/send.rb', line 98

def name
  @name
end

#typeObject

Returns the value of attribute type.



98
99
100
# File 'lib/spektr/exp/send.rb', line 98

def type
  @type
end

Instance Method Details

#expand!(ast, tree = []) ⇒ Object



125
126
127
128
129
130
131
132
# File 'lib/spektr/exp/send.rb', line 125

def expand!(ast, tree = [])
  if ast.is_a?(Parser::AST::Node) && ast.children.any?
    tree << ast.children.last
    expand!(ast.children.first, tree)
  else
    tree.reverse.join('.')
  end
end

#set_attributes(ast) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/spektr/exp/send.rb', line 105

def set_attributes(ast)
  if [:begin].include?(ast.type) && ast.children[0].is_a?(Parser::AST::Node)
    return set_attributes(ast.children[0])
  end

  @ast = ast
  if ast.type == :dstr
    @type = :dstr
    @name = ast.children[0].children.first
    ast.children[1..].each do |ch|
      @children << Receiver.new(ch)
    end
  else
    @expanded = expand!(ast)
    @ast = ast.type == :send && ast.children[0].is_a?(Parser::AST::Node) ? ast.children[0] : ast
    @type = @ast.type
    @name = @ast.children.last
  end
end