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, #long_form, #nested?, #path, #qualified_form, #qualified_name, #short_form, #start_with?, #to_s

Constructor Details

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

Initialize the definition from the syntax tree node.



29
30
31
32
33
# File 'lib/decode/language/ruby/definition.rb', line 29

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

Instance Attribute Details

#nodeObject (readonly)

The parser syntax tree node.



40
41
42
# File 'lib/decode/language/ruby/definition.rb', line 40

def node
  @node
end

Instance Method Details

#multiline?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/decode/language/ruby/definition.rb', line 42

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

#nested_nameObject



35
36
37
# File 'lib/decode/language/ruby/definition.rb', line 35

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

#textObject

The source code associated with the definition.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/decode/language/ruby/definition.rb', line 48

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