Class: Decode::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/decode/segment.rb

Overview

A chunk of code with an optional preceeding comment block.

~~~ ruby # Get the first segment from a source file: segment = source.segments.first ~~~

Direct Known Subclasses

Language::Ruby::Segment

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(comments, language) ⇒ Segment

Returns a new instance of Segment.



32
33
34
35
# File 'lib/decode/segment.rb', line 32

def initialize(comments, language)
	@comments = comments
	@language = language
end

Instance Attribute Details

#commentsObject (readonly)

The preceeding comments.



39
40
41
# File 'lib/decode/segment.rb', line 39

def comments
  @comments
end

#languageObject (readonly)

The language of the code attached to this segment.



43
44
45
# File 'lib/decode/segment.rb', line 43

def language
  @language
end

Instance Method Details

#codeObject

The source code trailing the comments.



55
56
# File 'lib/decode/segment.rb', line 55

def code
end

#documentationObject

An interface for accsssing the documentation of the definition.



47
48
49
50
51
# File 'lib/decode/segment.rb', line 47

def documentation
	if @comments&.any?
		@documentation ||= Documentation.new(@comments, @language)
	end
end