Class: Decode::Language::Ruby::Definition

Inherits:
Definition
  • Object
show all
Defined in:
lib/decode/language/ruby/definition.rb

Overview

A Ruby-specific definition.

Instance Attribute Summary collapse

Attributes inherited from Definition

#comments, #language, #name, #parent

Instance Method Summary collapse

Methods inherited from Definition

#container?, #convert, #documentation, #inspect, #long_form, #nested?, #path, #path_name, #qualified_form, #qualified_name, #short_form, #start_with?

Constructor Details

#initialize(node, *arguments, **options) ⇒ Definition

Initialize the definition from the syntax tree node.



14
15
16
17
18
# File 'lib/decode/language/ruby/definition.rb', line 14

def initialize(node, *arguments, **options)
	super(*arguments, **options)
	
	@node = node
end

Instance Attribute Details

#nodeObject (readonly)

The parser syntax tree node.



25
26
27
# File 'lib/decode/language/ruby/definition.rb', line 25

def node
  @node
end

Instance Method Details

#locationObject



48
49
50
51
52
# File 'lib/decode/language/ruby/definition.rb', line 48

def location
	expression = @node.location.expression
	
	Location.new(expression.source_buffer.name, expression.line)
end

#multiline?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/decode/language/ruby/definition.rb', line 27

def multiline?
	@node.location.line != @node.location.last_line
end

#nested_nameObject



20
21
22
# File 'lib/decode/language/ruby/definition.rb', line 20

def nested_name
	"\##{@name}"
end

#textObject

The source code associated with the definition.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/decode/language/ruby/definition.rb', line 33

def text
	expression = @node.location.expression
	lines = expression.source.lines
	if lines.count == 1
		return lines.first
	else
		if indentation = expression.source_line[/\A\s+/]
			# Remove all the indentation:
			lines.each{|line| line.sub!(indentation, '')}
		end
		
		return lines.join
	end
end