Class: Fmt::Macro

Inherits:
Model
  • Object
show all
Defined in:
lib/fmt/models/macro.rb

Overview

Represents an uninvoked method call

A Macro is comprised of:

  1. name: Symbol
  2. arguments: Arguments

Instance Attribute Summary collapse

Attributes inherited from Model

#ast, #source, #urtext

AST Processors collapse

Instance Method Summary collapse

Methods inherited from Model

#inspect, #self?

Methods included from Matchable

#deconstruct, #deconstruct_keys

Constructor Details

#initialize(ast) ⇒ Macro

Constructor



18
19
20
21
22
# File 'lib/fmt/models/macro.rb', line 18

def initialize(ast)
  @name = nil
  @arguments = Arguments.new(Node.new(:arguments))
  super
end

Instance Attribute Details

#argumentsObject (readonly)

: Arguments



14
15
16
# File 'lib/fmt/models/macro.rb', line 14

def arguments
  @arguments
end

#nameObject (readonly)

: Symbol -- method name



13
14
15
# File 'lib/fmt/models/macro.rb', line 13

def name
  @name
end

Instance Method Details

#on_arguments(node) ⇒ Object

Processes an arguments AST node



54
55
56
# File 'lib/fmt/models/macro.rb', line 54

def on_arguments(node)
  @arguments = Arguments.new(node)
end

#on_macro(node) ⇒ Object

Processes a macro AST node



40
41
42
# File 'lib/fmt/models/macro.rb', line 40

def on_macro(node)
  process_all node.children
end

#on_name(node) ⇒ Object

Processes a procedure AST node



47
48
49
# File 'lib/fmt/models/macro.rb', line 47

def on_name(node)
  @name = node.find(Symbol)
end

#to_hObject

Hash representation of the model (required for pattern matching)



26
27
28
29
30
31
# File 'lib/fmt/models/macro.rb', line 26

def to_h
  super.merge(
    name: name,
    arguments: arguments&.to_h
  )
end