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.



17
18
19
20
# File 'lib/decode/segment.rb', line 17

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

Instance Attribute Details

#commentsObject (readonly)

The preceeding comments.



24
25
26
# File 'lib/decode/segment.rb', line 24

def comments
  @comments
end

#languageObject (readonly)

The language of the code attached to this segment.



28
29
30
# File 'lib/decode/segment.rb', line 28

def language
  @language
end

Instance Method Details

#codeObject

The source code trailing the comments.



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

def code
end

#documentationObject

An interface for accsssing the documentation of the definition.



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

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