Class: Decode::Documentation

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

Constant Summary collapse

DESCRIPTION =
/\A\s*([^@\s].*)?\z/
ATTRIBUTE =
/\A\s*@(?<name>.*?)\s+(?<value>.*?)\z/
PARAMETER =
/\A\s*@param\s+(?<name>.*?)\s+\[(?<type>.*?)\]\s+(?<details>.*?)\z/

Instance Method Summary collapse

Constructor Details

#initialize(comments) ⇒ Documentation

Returns a new instance of Documentation.



23
24
25
# File 'lib/decode/documentation.rb', line 23

def initialize(comments)
	@comments = comments
end

Instance Method Details

#attributesObject



55
56
57
58
59
60
61
62
63
# File 'lib/decode/documentation.rb', line 55

def attributes
	return to_enum(:attributes) unless block_given?
	
	@comments.each do |comment|
		if match = comment.match(ATTRIBUTE)
			yield match
		end
	end
end

#descriptionObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/decode/documentation.rb', line 29

def description
	return to_enum(:description) unless block_given?
	
	# We track empty lines and only yield a single empty line when there is another line of text:
	gap = false
	
	@comments.each do |comment|
		if match = comment.match(DESCRIPTION)
			if match[1]
				if gap
					yield ""
					gap = false
				end
				
				yield match[1]
			else
				gap = true
			end
		else
			break
		end
	end
end

#parametersObject



67
68
69
70
71
72
73
74
75
# File 'lib/decode/documentation.rb', line 67

def parameters
	return to_enum(:parameters) unless block_given?
	
	@comments.each do |comment|
		if match = comment.match(PARAMETER)
			yield match
		end
	end
end