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

Initialize a new segment.



20
21
22
23
24
# File 'lib/decode/segment.rb', line 20

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

Instance Attribute Details

#commentsObject (readonly)

Returns the value of attribute comments.



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

def comments
  @comments
end

#languageObject (readonly)

Returns the value of attribute language.



30
31
32
# File 'lib/decode/segment.rb', line 30

def language
  @language
end

#The language of the code attached to this segment.(languageofthecodeattachedtothissegment.) ⇒ Object (readonly)



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

attr :language

#The preceeding comments.(preceedingcomments.) ⇒ Object (readonly)



27
# File 'lib/decode/segment.rb', line 27

attr :comments

Instance Method Details

#codeObject

The source code trailing the comments.



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

def code
end

#documentationObject

An interface for accsssing the documentation of the definition.



34
35
36
37
38
# File 'lib/decode/segment.rb', line 34

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