Class: Umwelt::Semantic::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/umwelt/semantic.rb

Direct Known Subclasses

Plain::Base

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node:) ⇒ Base

Returns a new instance of Base.



11
12
13
# File 'lib/umwelt/semantic.rb', line 11

def initialize(node:)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



9
10
11
# File 'lib/umwelt/semantic.rb', line 9

def node
  @node
end

Instance Method Details

#ancestry_pathObject



19
20
21
22
23
24
# File 'lib/umwelt/semantic.rb', line 19

def ancestry_path
  ancestry
    .collect(&:body)
    .map { |body| underscore(body) }
    .join '/'
end

#codeObject



26
27
28
# File 'lib/umwelt/semantic.rb', line 26

def code
  Unparser.unparse(ast)
end

#contextObject

nil check for case of root node, which has not context



38
39
40
# File 'lib/umwelt/semantic.rb', line 38

def context
  node.context&.semantic(:Plain)
end

#csymbolObject

classified symbol



43
44
45
# File 'lib/umwelt/semantic.rb', line 43

def csymbol
  classify(body).to_sym
end

#labelObject



47
48
49
# File 'lib/umwelt/semantic.rb', line 47

def label
  self.class.name.split('::').last.to_sym
end

#path(location: nil) ⇒ Object

default_location defined, for example, in Semantic::Plain::Base or base file from another semantic



33
34
35
# File 'lib/umwelt/semantic.rb', line 33

def path(location: nil)
  Pathname.pwd / (location || default_location) / tail_path
end

#s(type, *children) ⇒ Object



15
16
17
# File 'lib/umwelt/semantic.rb', line 15

def s(type, *children)
  Parser::AST::Node.new(type, children)
end

#tail_pathObject



51
52
53
# File 'lib/umwelt/semantic.rb', line 51

def tail_path
  Pathname.new(ancestry_path).sub_ext('.rb')
end